wasp_general.network package

Subpackages

Submodules

wasp_general.network.primitives module

class wasp_general.network.primitives.WFQDN(address=None)[source]

Bases: object

Represent single fully qualified domain name (FQDN).

see also https://en.wikipedia.org/wiki/Fully_qualified_domain_name

static from_string(address)[source]

Convert doted-written FQDN address to WFQDN object

Parameters:address – address to convert
Returns:WFQDN
maximum_fqdn_length = 253
static punycode(idn_fqdn)[source]

Create WFQDN from IDN (Internationalized domain name) by reverting it to punycode

Parameters:idn_fqdn – internationalized domain name to convert
Returns:WFQDN

see also https://en.wikipedia.org/wiki/Internationalized_domain_name see also https://en.wikipedia.org/wiki/Punycode

re_label = re.compile('^[a-zA-Z0-9\\-]{1,63}$')

Regular expression for FQDN label (sequence between dots) as is specified in ….

static to_string(address, leading_dot=False)[source]

Return doted-written address by the given WFQDN object

Parameters:
  • address – address to convert
  • leading_dot – whether this function place leading dot to the result or not
Returns:

str

class wasp_general.network.primitives.WIPPort(port)[source]

Bases: object

Represent TCP/UDP IP port

see also: https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_ports https://en.wikipedia.org/wiki/User_Datagram_Protocol#Service_ports

maximum_port_number = 65535

Maximum port number

minimum_port_number = 1

Minimum port number

class wasp_general.network.primitives.WIPV4Address(address=None)[source]

Bases: object

Represent IPv4 address.

see also https://en.wikipedia.org/wiki/IPv4#Address_representations

bin_address()[source]

Convert address to WBinArray

Returns:WBinArray
static from_string(address)[source]

Parse string for IPv4 address

Parameters:address – address to parse
Returns:
octet_count = 4

Address bytes count

static to_string(address, dns_format=False)[source]

Convert address to string

Parameters:
  • address – WIPV4Address to convert
  • dns_format – whether to use arpa-format or not
Returns:

class wasp_general.network.primitives.WIPV4SocketInfo(address=None, port=None)[source]

Bases: object

Represent socket information - IP address (or domain name) and port number. Mainly used for python socket module.

see WIPV4SocketInfo.pair()

address()[source]

Return associated IP address or None if not available

Returns:WIPV4Address or WFQDN or None
pair()[source]

Return tuple (address, port), where address is a string (empty string if self.address() is None) and port is an integer (zero if self.port() is None). Mainly, this tuple is used with python socket module (like in bind method)

Returns:2 value tuple of str and int.
static parse_address(address)[source]

Parse string and return WIPV4Address object if an IP address is specified, WFQDN if domain name is specified and None if the string is empty.

Parameters:address – string to parse
Returns:WIPV4Address or WFQDN or None
classmethod parse_socket_info(info)[source]

Parse string that is formed like ‘[address]<:port>’ and return corresponding WIPV4ScketInfo object

Parameters:info – string to parse
Returns:WIPV4ScketInfo
port()[source]

Return associated IP port or None if not available

Returns:WIPPort or None
class wasp_general.network.primitives.WMACAddress(address=None)[source]

Bases: object

Represent Ethernet/WiFi MAC address.

see also https://en.wikipedia.org/wiki/MAC_address

bin_address()[source]

Get this address as sequence of bits

Returns:WBinArray
static from_string(address)[source]

Return new object by the given MAC-address

Parameters:address – address to convert
Returns:WMACAddress
octet_count = 6

Address bytes count

re_cisco_format = re.compile('^[0-9a-fA-F]{4}.[0-9a-fA-F]{4}.[0-9a-fA-F]{4}$')

Regular expression for MAC address written in “Cisco” style like ‘0011.2233.4455’

re_colon_format = re.compile('^[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}$')

Regular expression for “colon”-written MAC address like ‘00:11:22:33:44:55’

re_dash_format = re.compile('^[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}-[0-9a-fA-F]{2}$')

Regular expression for “dash”-written MAC address like ‘00-11-22-33-44-55’

re_spaceless_format = re.compile('^[0-9a-fA-F]{12}$')

Regular expression for MAC address written without separator like ‘001122334455’

class wasp_general.network.primitives.WNetworkIPV4(address, network_address=True)[source]

Bases: object

This class represent IPv4 network address. Depends on a flag network_address (that is passed to constructor) object can represent separate host address with network mask or be an address of a IP network.

see also https://en.wikipedia.org/wiki/IPv4

address()[source]

Return IP address

Returns:WIPV4Address
delimiter = '/'

Separator that separate network address from network mask.

first_address(skip_network_address=True)[source]

Return the first IP address of this network

Parameters:skip_network_address – this flag specifies whether this function returns address of the network or returns address that follows address of the network (address, that a host could have)
Returns:WIPV4Address
static is_multicast(address)[source]

Check if address is a multicast address.

Parameters:address – IP address to check
Returns:bool

see also https://tools.ietf.org/html/rfc5771

iterator(skip_network_address=True, skip_broadcast_address=True)[source]

Return iterator, that can iterate over network addresses

Parameters:
  • skip_network_address – same as skip_network_address in NetworkIPV4.first_address() method
  • skip_broadcast_address – same as skip_broadcast_address in NetworkIPV4.last_address() method
Returns:

NetworkIPV4Iterator

last_address(skip_broadcast_address=True)[source]

Return the last IP address of this network

Parameters:skip_broadcast_address – this flag specifies whether to skip the very last address (that is usually used as broadcast address) or not.
Returns:WIPV4Address
mask()[source]

Return network mask (as bits count)

Returns:int
class wasp_general.network.primitives.WNetworkIPV4Iterator(network, skip_network_address=True, skip_broadcast_address=True)[source]

Bases: object

This iterator iterates over IP network addresses.

wasp_general.network.service module

class wasp_general.network.service.WBasicNativeSocketHandler(transport, config, io_handler)[source]

Bases: wasp_general.network.service.WIOLoopServiceHandler

Basic WIOLoopServiceHandler implementation. Since some WNetworkNativeTransportProto methods are required WConfig object, then that kind of object is required for this class instantiation

config()[source]

Return handler configuration

Returns:WConfig
io_handler()[source]

Return IO-handler

Returns:WNativeSocketIOHandler
transport()[source]

Return currently used transport :return: WNetworkNativeTransportProto

class wasp_general.network.service.WIOLoopService(handler, loop=None, timeout=None)[source]

Bases: object

Represent service (or service client) that works over tornado IOLoop

handler()[source]

Return service handler

Returns:WIOLoopServiceHandler
loop()[source]

Return service loop object

Returns:IOLoop
start()[source]

Set up handler and start loop

Returns:None
stop()[source]

Stop loop

Returns:None
timeout()[source]

Return service timeout. (None for endless loop)

Returns:int or None
class wasp_general.network.service.WIOLoopServiceHandler[source]

Bases: object

Represent service (or service client) handler that works with tornado IOLoop and do the work.

loop_stopped()[source]

Method is called when previously set up loop was stopped

Returns:None
setup_handler(io_loop)[source]

Set up this handler with the specified IOLoop

Parameters:io_loop – service (or service client) loop to use with
Returns:None
class wasp_general.network.service.WLoglessIOLoop(*args, **kwargs)[source]

Bases: zmq.eventloop.ioloop.ZMQIOLoop

class wasp_general.network.service.WNativeSocketDirectIOHandler[source]

Bases: wasp_general.network.service.WNativeSocketIOHandler

This type of IO-handler has access to low-level socket object

transport_socket(new_socket=None)[source]

Save and/or return currently used socket object

Parameters:new_socket – new socket to save
Returns:socket object (any type, None if socket wasn’t set)
class wasp_general.network.service.WNativeSocketHandler(transport, config, io_handler, server_mode)[source]

Bases: wasp_general.network.service.WBasicNativeSocketHandler

Enhanced variant of WBasicNativeSocketHandler class. This class support ‘server_mode’ flag and is capable to set up the specified IO-handler with WIOLoopService service

loop_stopped()[source]

Terminate socket connection because of stopping loop

Returns:None
server_mode()[source]

Return current mode. True if this handler works as a server, otherwise - False

Returns:bool
setup_handler(io_loop)[source]

WIOLoopServiceHandler.setup_handler() implementation. If WNativeSocketDirectIOHandler is used as a io-handler, then socket object is saved to this handler before loop starting

Parameters:io_loop – io_loop to use
Returns:None
class wasp_general.network.service.WNativeSocketIOHandler[source]

Bases: object

Handler prototype for loops that work with WNetworkNativeTransportProto transports. It is used by WBasicNativeSocketHandler handler and do all the work for this class.

handler_fn(fd, event)[source]

Process (handle) specified event

Parameters:
  • fd – integer file descriptor or a file-like object with a fileno() method
  • event – IOLoop event
Returns:

None

class wasp_general.network.service.WZMQHandler(context=None)[source]

Bases: wasp_general.network.service.WIOLoopServiceHandler

class BindSetupAgent(socket_type, connection, *socket_options)[source]

Bases: wasp_general.network.service.SetupAgent

create_socket(handler)[source]
class ConnectSetupAgent(socket_type, connection, *socket_options)[source]

Bases: wasp_general.network.service.SetupAgent

create_socket(handler)[source]
class ReceiveAgent[source]

Bases: object

on_receive(handler, msg)[source]
setup_receiver(handler)[source]
class SendAgent[source]

Bases: object

send(handler, data)[source]
class SetupAgent(socket_type, connection, *socket_options)[source]

Bases: object

connection()[source]
create_socket(handler)[source]
setup_handler(handler, io_loop)[source]
setup_receiver(handler, receive_agent)[source]
socket_options()[source]
socket_type()[source]
class SocketOption(name, value)[source]

Bases: object

configure(setup_agent, receive_agent=None)[source]
context()[source]
receive_agent()[source]
setup_agent()[source]
setup_handler(io_loop)[source]
stream()[source]
class wasp_general.network.service.WZMQService(setup_agent, loop=None, handler=None, receive_agent=None, timeout=None)[source]

Bases: wasp_general.network.service.WIOLoopService

discard_queue_messages()[source]

Sometimes it is necessary to drop undelivered messages. These messages may be stored in different caches, for example in a zmq socket queue. With different zmq flags we can tweak zmq sockets and contexts no to keep those messages. But inside ZMQStream class there is a queue that can not be cleaned other way then the way it does in this method. So yes, it is dirty to access protected members, and yes it can be broken at any moment. And yes without correct locking procedure there is a possibility of unpredicted behaviour. But still - there is no other way to drop undelivered messages

Discussion of the problem: https://github.com/zeromq/pyzmq/issues/1095

Returns:None
class wasp_general.network.service.WZMQSyncAgent(timeout=None)[source]

Bases: wasp_general.network.service.ReceiveAgent

data()[source]
event()[source]
handler()[source]
on_receive(handler, msg)[source]
receive()[source]
setup_receiver(handler)[source]
timeout()[source]

wasp_general.network.transport module

class wasp_general.network.transport.WBroadcastNetworkTransport(target_socket_config, bind_socket_config)[source]

Bases: wasp_general.network.transport.WUDPNetworkNativeTransport

Network transport, that uses IPv4 broadcast (UDP) communication

create_client_socket(config)[source]

Create client broadcast socket

Parameters:config – client configuration
Returns:socket.socket
target_socket(config)[source]

This method overrides WNetworkNativeTransport.target_socket() method. Do the same thing as basic method do, but also checks that the result address is IPv4 address.

Parameters:config – beacon configuration
Returns:WIPV4SocketInfo
class wasp_general.network.transport.WMulticastNetworkTransport(target_socket_config, bind_socket_config)[source]

Bases: wasp_general.network.transport.WUDPNetworkNativeTransport

Network transport, that uses IPv4 multicast communication

create_server_socket(config)[source]

Create server multicast socket. Socket will be joined to the multicast-group (same as it is specified in client configuration, same as client does)

Parameters:config – server configuration
Returns:socket.socket
target_socket(config)[source]

This method overrides WNetworkNativeTransport.target_socket() method. Do the same thing as basic method do, but also checks that the result address is IPv4 multicast address.

Parameters:config – beacon configuration
Returns:WIPV4SocketInfo
class wasp_general.network.transport.WNetworkNativeTransport(target_socket_config, bind_socket_config)[source]

Bases: wasp_general.network.transport.WNetworkNativeTransportProto

Basic WNetworkNativeTransportProto implementation. This class isn’t ready to use, but it has general implementation for the most WNetworkNativeTransportProto methods.

bind_socket(config)[source]

WNetworkNativeTransportProto.bind_socket() method implementation

client_socket(config)[source]

WNetworkNativeTransportProto.client_socket() method implementation

close_client_socket(config, close_fd=True)[source]

WNetworkNativeTransportProto.close_client_socket() method implementation

close_server_socket(config, close_fd=True)[source]

WNetworkNativeTransportProto.close_server_socket() method implementation

create_client_socket(config)[source]

Create socket for client. (By default, same as WNetworkNativeTransport._create_socket)

Parameters:config – client configuration
Returns:socket.socket
create_server_socket(config)[source]

Create socket for server. (By default, same as WNetworkNativeTransport._create_socket)

Parameters:config – server configuration
Returns:socket.socket
server_socket(config)[source]

WNetworkNativeTransportProto.server_socket() method implementation

target_socket(config)[source]

WNetworkNativeTransportProto.server_socket() method implementation

class wasp_general.network.transport.WNetworkNativeTransportProto[source]

Bases: object

This is interface for classes, that implement transport logic for network communication. “Native” means that these classes use socket objects directly.

bind_socket(config)[source]

Return socket information with address that server binds to.

Parameters:config – server configuration
Returns:WIPV4SocketInfo
client_socket(config)[source]

Return client socket. This socket is used for sending request and receiving results. It is important, that the result can be polled by a IOLoop instance.

Parameters:config – client configuration
Returns:socket.socket
close_client_socket(config, close_fd=True)[source]

Close previously opened client socket. If no socket is opened - do nothing.

Parameters:
  • config – client configuration
  • close_fd – should this function close socket fd, or will it close by an external function?. It is safer to pass True here.
Returns:

None

close_server_socket(config, close_fd=True)[source]

Close previously opened server socket. If no socket is opened - do nothing.

Parameters:
  • config – server configuration
  • close_fd – should this function close socket fd, or will it close by an external function?. It is safer to pass True here.
Returns:

None

server_socket(config)[source]

Return server socket. This socket is used for receiving requests and sending results. It is important, that the result can be polled by a IOLoop instance.

Parameters:config – server configuration
Returns:socket.socket
target_socket(config)[source]

Return socket information with server address. Mostly used for address validation.

Parameters:config – client configuration
Returns:WIPV4SocketInfo
class wasp_general.network.transport.WNetworkNativeTransportSocketConfig(section, address_option, port_option)[source]

Bases: object

Represent socket configuration settings.

class wasp_general.network.transport.WTCPNetworkNativeTransport(target_socket_config, bind_socket_config)[source]

Bases: wasp_general.network.transport.WNetworkNativeTransport

Basic TCP transport implementation

class wasp_general.network.transport.WUDPNetworkNativeTransport(target_socket_config, bind_socket_config)[source]

Bases: wasp_general.network.transport.WNetworkNativeTransport

Basic UDP transport implementation

wasp_general.network.upload module

class wasp_general.network.upload.WBasicUploader(scheme, supported_options, required_options)[source]

Bases: wasp_general.network.upload.WUploaderProto

is_capable(scheme, options)[source]
required_options()[source]
scheme()[source]
supported_options()[source]
upload(file_obj, options)[source]
class wasp_general.network.upload.WFTPUploader[source]

Bases: wasp_general.network.upload.WBasicUploader

is_capable(scheme, options)[source]
class wasp_general.network.upload.WUploaderCollection(*uploaders)[source]

Bases: wasp_general.network.upload.WUploaderProto

is_capable(scheme, options)[source]
upload(url, file_name)[source]
uploaders()[source]
class wasp_general.network.upload.WUploaderProto[source]

Bases: object

class URLOption[source]

Bases: enum.Enum

An enumeration.

fragment = 7
hostname = 0
params = 5
password = 2
path = 4
port = 3
query = 6
username = 1
is_capable(scheme, options)[source]
upload(file_obj, options)[source]

Module contents