signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
@abstractmethod<EOL><INDENT>def message(self):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Return real message. It can be anything - string, bytes, structure... :return: any-type object or None
f9855:c1:m0
def meta(self):
return {}<EOL>
Return message meta data (dictionary object). For dictionary keys, values usage scenario see current implementation (:class:`.WMessengerEnvelope`) :return: dict
f9855:c1:m1
@abstractmethod<EOL><INDENT>def onion(self):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Return related onion. In most cases, it is the onion, that creates this session. :return: WMessengerOnionProto
f9855:c2:m0
@abstractmethod<EOL><INDENT>@verify_type(envelope=(WMessengerEnvelopeProto, None))<EOL>def process(self, envelope):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Parse message, process it and generate response :param envelope: incoming or outgoing message or nothing. This value is passed to the first layer as is. :return: outgoing message or nothing. In most cases, this is a server response or client request.
f9855:c2:m1
@verify_type(name=str)<EOL><INDENT>def __init__(self, name):<DEDENT>
self.__name = name<EOL>
Construct new layer with the given name :param name: name of the layer
f9855:c3:m0
def name(self):
return self.__name<EOL>
Return the layer name :return: str
f9855:c3:m1
@abstractmethod<EOL><INDENT>@verify_type(envelope=WMessengerEnvelopeProto, session=WMessengerOnionSessionProto)<EOL>def process(self, envelope, session, **kwargs):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Parse/combine, decrypt/encrypt, decode/encode message. :param envelope: message to parse/combine/decrypt/encrypt/decode/encode :param session: related session :param kwargs: arguments that help to customize a layer (they are set in \ :class:`.WMessengerOnionSessionFlowProto.IteratorInfo` objects) :return: WMessengerEnvelopeProto
f9855:c3:m2
@abstractmethod<EOL><INDENT>@verify_type(envelope=WMessengerEnvelopeProto)<EOL>def iterator(self, envelope):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Return iterator to be used for message processing. Iterator may depend on incoming message :param envelope: original incoming message :return: WMessengerOnionSessionFlowProto.Iterator or None if there is no way to create session for the \ given message
f9855:c4:m0
@verify_type(iterator=WMessengerOnionSessionFlowProto.Iterator)<EOL><INDENT>def __init__(self, iterator):<DEDENT>
WMessengerOnionSessionFlowProto.__init__(self)<EOL>self.__iterator = iterator<EOL>
Construct new session flow :param iterator: flow iterator
f9856:c0:m0
@verify_type('<STR_LIT>', envelope=WMessengerEnvelopeProto)<EOL><INDENT>def iterator(self, envelope):<DEDENT>
return self.__iterator<EOL>
:meth:`.WMessengerOnionSessionFlowProto.iterator` implementation
f9856:c0:m1
@classmethod<EOL><INDENT>@verify_type(info=WMessengerOnionSessionFlowProto.IteratorInfo)<EOL>def sequence(cls, *info):<DEDENT>
if len(info) == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>info = list(info)<EOL>info.reverse()<EOL>result = WMessengerOnionSessionFlowProto.Iterator(<EOL>info[<NUM_LIT:0>].layer_name(), **info[<NUM_LIT:0>].layer_args()<EOL>)<EOL>for i in range(<NUM_LIT:1>, len(info)):<EOL><INDENT>result = WMessengerOnionSessionFlowProto.Iterator(<EOL>info[i].layer_name(), next_iterator=result, **info[i].layer_args()<EOL>)<EOL><DEDENT>return result<EOL>
Useful method to generate iterator. It is generated by chaining the given info. If no info is specified, then None is returned :param info: iterator info sequence :return: WMessengerOnionSessionFlowProto.Iterator or None
f9856:c0:m2
@staticmethod<EOL><INDENT>@verify_type('<STR_LIT>', info=WMessengerOnionSessionFlowProto.IteratorInfo)<EOL>def sequence_flow(*info):<DEDENT>
if len(info) > <NUM_LIT:0>:<EOL><INDENT>return WMessengerOnionSessionFlow(WMessengerOnionSessionFlow.sequence(*info))<EOL><DEDENT>
Same method as :meth:`.WMessengerOnionSessionFlow.sequence`, but as a result :class:`.WMessengerOnionSessionFlow` object created (if no info is specified, then None is returned) :param info: iterator info sequence :return: WMessengerOnionSessionFlow or None
f9856:c0:m3
@verify_type(flows=WMessengerOnionSessionFlowProto)<EOL><INDENT>def __init__(self, *flows):<DEDENT>
WMessengerOnionSessionFlowProto.__init__(self)<EOL>self.__flows = flows<EOL>
Construct new session flow :param flows: flows to iterate
f9856:c1:m0
@verify_type('<STR_LIT>', envelope=WMessengerEnvelopeProto)<EOL><INDENT>def iterator(self, envelope):<DEDENT>
iterator = WMessengerOnionSessionFlowSequence.FlowSequenceIterator(<EOL>WMessengerOnionSessionFlowProto.IteratorInfo('<STR_LIT>'), *self.__flows<EOL>)<EOL>return iterator.next(envelope)<EOL>
:meth:`WMessengerOnionSessionFlowProto.iterator` implementation
f9856:c1:m1
@verify_type(default_flow=(WMessengerOnionSessionFlowProto, None))<EOL><INDENT>def __init__(self, *flow_comparator_pairs, default_flow=None):<DEDENT>
WMessengerOnionSessionFlowProto.__init__(self)<EOL>self.__pairs = []<EOL>for pair in flow_comparator_pairs:<EOL><INDENT>if isinstance(pair, WMessengerOnionSessionFlexFlow.FlowComparatorPair) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>self.__pairs.append(pair)<EOL><DEDENT>self.__default_flow = default_flow<EOL>
Construct new session flow :param flow_comparator_pairs: flows to check :param default_flow: default flow (if no flow is matched)
f9856:c2:m0
@verify_type('<STR_LIT>', envelope=WMessengerEnvelopeProto)<EOL><INDENT>def iterator(self, envelope):<DEDENT>
for pair in self.__pairs:<EOL><INDENT>if pair.comparator().match(envelope) is True:<EOL><INDENT>return pair.flow().iterator(envelope)<EOL><DEDENT><DEDENT>if self.__default_flow is not None:<EOL><INDENT>return self.__default_flow.iterator(envelope)<EOL><DEDENT>
:meth:`WMessengerOnionSessionFlowProto.iterator` implementation
f9856:c2:m1
@verify_type(onion=WMessengerOnionProto, session_flow=WMessengerOnionSessionFlowProto)<EOL><INDENT>def __init__(self, onion, session_flow):<DEDENT>
self.__onion = onion<EOL>self.__session_flow = session_flow<EOL>
Construct new session. :param onion: related onion :param session_flow: defines layers order to be executed
f9856:c3:m0
def onion(self):
return self.__onion<EOL>
:meth:`.WMessengerOnionSessionProto.onion` method implementation.
f9856:c3:m1
def session_flow(self):
return self.__session_flow<EOL>
Return related :class:`.WMessengerOnionSessionFlow` object :return: WMessengerOnionSessionFlow
f9856:c3:m2
@verify_type('<STR_LIT>', envelope=WMessengerEnvelopeProto)<EOL><INDENT>def process(self, envelope):<DEDENT>
def process_single_layer(iter_envelope, iter_obj):<EOL><INDENT>layer = self.onion().layer(iter_obj.layer_name())<EOL>layer_args = iter_obj.layer_args()<EOL>return layer.process(iter_envelope, self, **layer_args)<EOL><DEDENT>iterator = self.session_flow().iterator(envelope)<EOL>if iterator is not None:<EOL><INDENT>while iterator is not None:<EOL><INDENT>envelope = process_single_layer(envelope, iterator)<EOL>iterator = iterator.next(envelope)<EOL><DEDENT><DEDENT>return envelope<EOL>
:meth:`.WMessengerOnionSessionProto.process` method implementation.
f9856:c3:m3
def __init__(self):
WMessengerOnionCoderLayerProto.__init__(self, WMessengerFixedModificationLayer.__layer_name__)<EOL>
Construct new layer
f9857:c0:m0
@verify_type(envelope=(WMessengerTextEnvelope, WMessengerBytesEnvelope))<EOL><INDENT>def __args_check(self, envelope, target, modification_code):<DEDENT>
if target is None:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if modification_code is None:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if isinstance(target, WMessengerFixedModificationLayer.Target) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if isinstance(envelope, WMessengerTextEnvelope) is True:<EOL><INDENT>if isinstance(modification_code, str) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT><DEDENT>elif isinstance(modification_code, bytes) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>
Method checks arguments, that are specified to the :meth:`.WMessengerFixedModificationLayer.encode` and :meth:`.WMessengerFixedModificationLayer.decode` methods :param envelope: same as envelope in :meth:`.WMessengerFixedModificationLayer.encode` and \ :meth:`.WMessengerFixedModificationLayer.decode` methods :param target: same as target in :meth:`.WMessengerFixedModificationLayer.encode` and \ :meth:`.WMessengerFixedModificationLayer.decode` methods :param modification_code: same as modification_code in \ :meth:`.WMessengerFixedModificationLayer.encode` and :meth:`.WMessengerFixedModificationLayer.decode` \ methods :return: None
f9857:c0:m1
@verify_type('<STR_LIT>', envelope=(WMessengerTextEnvelope, WMessengerBytesEnvelope))<EOL><INDENT>@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto)<EOL>def encode(self, envelope, session, target=None, modification_code=None, **kwargs):<DEDENT>
self.__args_check(envelope, target, modification_code)<EOL>if isinstance(envelope, WMessengerTextEnvelope):<EOL><INDENT>target_envelope_cls = WMessengerTextEnvelope<EOL><DEDENT>else: <EOL><INDENT>target_envelope_cls = WMessengerBytesEnvelope<EOL><DEDENT>if target == WMessengerFixedModificationLayer.Target.head:<EOL><INDENT>return target_envelope_cls(modification_code + envelope.message(), meta=envelope)<EOL><DEDENT>else: <EOL><INDENT>return target_envelope_cls(envelope.message() + modification_code, meta=envelope)<EOL><DEDENT>
Methods appends 'modification_code' to the specified envelope. :param envelope: original envelope :param session: original session :param target: flag, that specifies whether code must be appended to the start or to the end :param modification_code: code to append :param kwargs: additional arguments :return: WMessengerTextEnvelope or WMessengerBytesEnvelope (depends on the original envelope)
f9857:c0:m2
@verify_type('<STR_LIT>', envelope=(WMessengerTextEnvelope, WMessengerBytesEnvelope))<EOL><INDENT>@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto)<EOL>def decode(self, envelope, session, target=None, modification_code=None, **kwargs):<DEDENT>
self.__args_check(envelope, target, modification_code)<EOL>message = envelope.message()<EOL>if len(message) < len(modification_code):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if isinstance(envelope, WMessengerTextEnvelope):<EOL><INDENT>target_envelope_cls = WMessengerTextEnvelope<EOL><DEDENT>else: <EOL><INDENT>target_envelope_cls = WMessengerBytesEnvelope<EOL><DEDENT>if target == WMessengerFixedModificationLayer.Target.head:<EOL><INDENT>if message[:len(modification_code)] != modification_code:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return target_envelope_cls(message[len(modification_code):], meta=envelope)<EOL><DEDENT>else: <EOL><INDENT>if message[-len(modification_code):] != modification_code:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return target_envelope_cls(message[:-len(modification_code)], meta=envelope)<EOL><DEDENT>
Methods checks envelope for 'modification_code' existence and removes it. :param envelope: original envelope :param session: original session :param target: flag, that specifies whether code must be searched and removed at the start or at the end :param modification_code: code to search/remove :param kwargs: additional arguments :return: WMessengerTextEnvelope or WMessengerBytesEnvelope (depends on the original envelope)
f9857:c0:m3
def __init__(self):
WMessengerOnionCoderLayerProto.__init__(self, WMessengerEncodingLayer.__layer_name__)<EOL>
Construct new layer
f9857:c1:m0
@verify_type('<STR_LIT>', envelope=WMessengerTextEnvelope, session=WMessengerOnionSessionProto)<EOL><INDENT>@verify_type(encoding=(str, None))<EOL>def encode(self, envelope, session, encoding=None, **kwargs):<DEDENT>
message = envelope.message()<EOL>message = message.encode() if encoding is None else message.encode(encoding)<EOL>return WMessengerBytesEnvelope(message, meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.encode` method implementation. :param envelope: original envelope :param session: original session :param encoding: encoding to use (default is 'utf-8') :param kwargs: additional arguments :return: WMessengerBytesEnvelope
f9857:c1:m1
@verify_type('<STR_LIT>', envelope=WMessengerBytesEnvelope, session=WMessengerOnionSessionProto)<EOL><INDENT>@verify_type(encoding=(str, None))<EOL>def decode(self, envelope, session, encoding=None, **kwargs):<DEDENT>
message = envelope.message()<EOL>message = message.decode() if encoding is None else message.decode(encoding)<EOL>return WMessengerTextEnvelope(message, meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.decode` method implementation. :param envelope: original envelope :param session: original session :param encoding: encoding to use (default is 'utf-8') :param kwargs: additional arguments :return: WMessengerTextEnvelope
f9857:c1:m2
def __init__(self):
WMessengerOnionCoderLayerProto.__init__(self, WMessengerHexLayer.__layer_name__)<EOL>
Construct new layer
f9857:c2:m0
@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto)<EOL><INDENT>@verify_type(envelope=WMessengerBytesEnvelope)<EOL>def encode(self, envelope, session, **kwargs):<DEDENT>
return WMessengerTextEnvelope(str(WHex(envelope.message())), meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.encode` method implementation. :param envelope: original envelope :param session: original session :param kwargs: additional arguments :return: WMessengerTextEnvelope
f9857:c2:m1
@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto)<EOL><INDENT>@verify_type(envelope=WMessengerTextEnvelope)<EOL>def decode(self, envelope, session, **kwargs):<DEDENT>
return WMessengerBytesEnvelope(bytes(WUnHex(envelope.message())), meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.decode` method implementation. :param envelope: original envelope :param session: original session :param kwargs: additional arguments :return: WMessengerBytesEnvelope
f9857:c2:m2
def __init__(self):
WMessengerOnionCoderLayerProto.__init__(self, WMessengerBase64Layer.__layer_name__)<EOL>
Construct new layer
f9857:c3:m0
@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto)<EOL><INDENT>@verify_type(envelope=WMessengerBytesEnvelope)<EOL>def encode(self, envelope, session, **kwargs):<DEDENT>
return WMessengerBytesEnvelope(b64encode(envelope.message()), meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.encode` method implementation. :param envelope: original envelope :param session: original session :param kwargs: additional arguments :return: WMessengerBytesEnvelope
f9857:c3:m1
@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto)<EOL><INDENT>@verify_type(envelope=WMessengerBytesEnvelope)<EOL>def decode(self, envelope, session, **kwargs):<DEDENT>
return WMessengerBytesEnvelope(b64decode(envelope.message()), meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.decode` method implementation. :param envelope: original envelope :param session: original session :param kwargs: additional arguments :return: WMessengerBytesEnvelope
f9857:c3:m2
def __init__(self):
WMessengerOnionCoderLayerProto.__init__(self, WMessengerAESLayer.__layer_name__)<EOL>
Construct new layer
f9857:c4:m0
@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto)<EOL><INDENT>@verify_type(envelope=WMessengerBytesEnvelope)<EOL>@verify_type(aes_cipher=WAES)<EOL>def encode(self, envelope, session, aes_cipher=None, **kwargs):<DEDENT>
return WMessengerBytesEnvelope(aes_cipher.encrypt(envelope.message()), meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.encode` method implementation. :param envelope: original envelope :param session: original session :param aes_cipher: cipher to use :param kwargs: additional arguments :return: WMessengerBytesEnvelope
f9857:c4:m1
@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto)<EOL><INDENT>@verify_type(envelope=WMessengerBytesEnvelope)<EOL>@verify_type(aes_cipher=WAES)<EOL>def decode(self, envelope, session, aes_cipher=None, **kwargs):<DEDENT>
return WMessengerBytesEnvelope(aes_cipher.decrypt(envelope.message(), decode=False), meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.decode` method implementation. :param envelope: original envelope :param session: original session :param aes_cipher: cipher to use :param kwargs: additional arguments :return: WMessengerBytesEnvelope
f9857:c4:m2
def __init__(self):
WMessengerOnionCoderLayerProto.__init__(self, WMessengerRSALayer.__layer_name__)<EOL>
Construct new layer
f9857:c5:m0
@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto, public_key=WRSA, oaep_hash_fn_name=(str, None))<EOL><INDENT>@verify_type('<STR_LIT>', mgf1_hash_fn_name=(str, None))<EOL>@verify_type(envelope=WMessengerBytesEnvelope)<EOL>@verify_value(public_key=lambda x: x.has_public_key() is True)<EOL>def encode(self, envelope, session, public_key=None, oaep_hash_fn_name=None, mgf1_hash_fn_name=None, **kwargs):<DEDENT>
message = public_key.encrypt(<EOL>envelope.message(), oaep_hash_fn_name=oaep_hash_fn_name, mgf1_hash_fn_name=mgf1_hash_fn_name<EOL>)<EOL>return WMessengerBytesEnvelope(message, meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.encode` method implementation. :param envelope: original envelope :param session: original session :param public_key: public key to encrypt :param oaep_hash_fn_name: OAEP hash function name :param mgf1_hash_fn_name: MGF1 hash function name :param kwargs: additional arguments :return: WMessengerBytesEnvelope
f9857:c5:m1
@verify_type('<STR_LIT>', session=WMessengerOnionSessionProto, private_key=WRSA, oaep_hash_fn_name=(str, None))<EOL><INDENT>@verify_type('<STR_LIT>', mgf1_hash_fn_name=(str, None))<EOL>@verify_type(envelope=WMessengerBytesEnvelope)<EOL>@verify_value(public_key=lambda x: x.has_private_key() is True)<EOL>def decode(self, envelope, session, private_key=None, oaep_hash_fn_name=None, mgf1_hash_fn_name=None, **kwargs):<DEDENT>
message = private_key.decrypt(<EOL>envelope.message(), oaep_hash_fn_name=oaep_hash_fn_name, mgf1_hash_fn_name=mgf1_hash_fn_name<EOL>)<EOL>return WMessengerBytesEnvelope(message, meta=envelope)<EOL>
:meth:`.WMessengerOnionCoderLayerProto.decode` method implementation. :param envelope: original envelope :param session: original session :param private_key: private key to decrypt :param oaep_hash_fn_name: hash function name :param mgf1_hash_fn_name: MGF1 hash function name :param kwargs: additional arguments :return: WMessengerBytesEnvelope
f9857:c5:m2
@verify_type(layers=WMessengerOnionLayerProto)<EOL><INDENT>def __init__(self, *layers):<DEDENT>
self.__layers = {}<EOL>self.add_layers(*layers)<EOL>
Construct new onion :param layers: layers to store
f9858:c0:m0
def layers_names(self):
return list(self.__class__.__builtin_layers__.keys()) + list(self.__layers.keys())<EOL>
:meth:`.WMessengerOnionProto.layer_names` method implementation.
f9858:c0:m1
@verify_type(layer_name=str)<EOL><INDENT>def layer(self, layer_name):<DEDENT>
if layer_name in self.__layers.keys():<EOL><INDENT>return self.__layers[layer_name]<EOL><DEDENT>elif layer_name in self.__class__.__builtin_layers__:<EOL><INDENT>return self.__class__.__builtin_layers__[layer_name]<EOL><DEDENT>raise RuntimeError('<STR_LIT>')<EOL>
:meth:`.WMessengerOnionProto.layer` method implementation.
f9858:c0:m2
@verify_type(layer=WMessengerOnionLayerProto)<EOL><INDENT>def add_layers(self, *layers):<DEDENT>
for layer in layers:<EOL><INDENT>if layer.name() in self.__layers.keys():<EOL><INDENT>raise ValueError('<STR_LIT>' % layer.name())<EOL><DEDENT>self.__layers[layer.name()] = layer<EOL><DEDENT>
Append given layers to this onion :param layers: layer to add :return: None
f9858:c0:m3
@verify_type('<STR_LIT>', address=(str, WBinArray, int, None))<EOL><INDENT>def __init__(self, address=None):<DEDENT>
self.__address = WFixedSizeByteArray(WMACAddress.octet_count)<EOL>if address is not None:<EOL><INDENT>if isinstance(address, str):<EOL><INDENT>self.__address = WFixedSizeByteArray(<EOL>WMACAddress.octet_count, WMACAddress.from_string(address).bin_address()<EOL>)<EOL><DEDENT>else:<EOL><INDENT>self.__address = WFixedSizeByteArray(WMACAddress.octet_count, address)<EOL><DEDENT><DEDENT>
Construct new address :param address: value with which this address is initialized (zeroes are used by default).
f9859:c0:m0
def bin_address(self):
return self.__address.bin_value()<EOL>
Get this address as sequence of bits :return: WBinArray
f9859:c0:m1
@staticmethod<EOL><INDENT>@verify_type(address=str)<EOL>def from_string(address):<DEDENT>
str_address = None<EOL>if WMACAddress.re_dash_format.match(address):<EOL><INDENT>str_address = "<STR_LIT>".join(address.split("<STR_LIT:->"))<EOL><DEDENT>elif WMACAddress.re_colon_format.match(address):<EOL><INDENT>str_address = "<STR_LIT>".join(address.split("<STR_LIT::>"))<EOL><DEDENT>elif WMACAddress.re_cisco_format.match(address):<EOL><INDENT>str_address = "<STR_LIT>".join(address.split("<STR_LIT:.>"))<EOL><DEDENT>elif WMACAddress.re_spaceless_format.match(address):<EOL><INDENT>str_address = address<EOL><DEDENT>if str_address is None:<EOL><INDENT>raise ValueError("<STR_LIT>" + address)<EOL><DEDENT>result = WMACAddress()<EOL>for octet_index in range(WMACAddress.octet_count):<EOL><INDENT>octet = str_address[:<NUM_LIT:2>]<EOL>result.__address[octet_index] = int(octet, <NUM_LIT:16>)<EOL>str_address = str_address[<NUM_LIT:2>:]<EOL><DEDENT>return result<EOL>
Return new object by the given MAC-address :param address: address to convert :return: WMACAddress
f9859:c0:m2
def __str__(self):
address = ["<STR_LIT>".format(int(x)) for x in self.__address]<EOL>return '<STR_LIT::>'.join(address)<EOL>
Convert to string :return: str
f9859:c0:m3
def __bytes__(self):
return bytes(self.__address)<EOL>
Convert to bytes :return: bytes
f9859:c0:m4
@verify_type('<STR_LIT>', address=(str, bytes, WBinArray, int, None))<EOL><INDENT>def __init__(self, address=None):<DEDENT>
self.__address = WFixedSizeByteArray(WIPV4Address.octet_count)<EOL>if address is not None:<EOL><INDENT>if isinstance(address, str):<EOL><INDENT>self.__address = WFixedSizeByteArray(<EOL>WIPV4Address.octet_count, WIPV4Address.from_string(address).bin_address()<EOL>)<EOL><DEDENT>else:<EOL><INDENT>self.__address = WFixedSizeByteArray(WIPV4Address.octet_count, address)<EOL><DEDENT><DEDENT>
Create new address :param address: value with which this address is initialized (zeroes are used by default).
f9859:c1:m0
def bin_address(self):
return self.__address.bin_value()<EOL>
Convert address to WBinArray :return: WBinArray
f9859:c1:m1
def __bytes__(self):
return bytes(self.__address)<EOL>
Convert address to bytes :return: bytes
f9859:c1:m2
@staticmethod<EOL><INDENT>@verify_type(address=str)<EOL>def from_string(address):<DEDENT>
address = address.split('<STR_LIT:.>')<EOL>if len(address) != WIPV4Address.octet_count:<EOL><INDENT>raise ValueError('<STR_LIT>' % address)<EOL><DEDENT>result = WIPV4Address()<EOL>for i in range(WIPV4Address.octet_count):<EOL><INDENT>result.__address[i] = WBinArray(int(address[i]), WFixedSizeByteArray.byte_size)<EOL><DEDENT>return result<EOL>
Parse string for IPv4 address :param address: address to parse :return:
f9859:c1:m3
@staticmethod<EOL><INDENT>@verify_type(dns_format=bool)<EOL>def to_string(address, dns_format=False):<DEDENT>
if isinstance(address, WIPV4Address) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>address = [str(int(x)) for x in address.__address]<EOL>if dns_format is False:<EOL><INDENT>return '<STR_LIT:.>'.join(address)<EOL><DEDENT>address.reverse()<EOL>return ('<STR_LIT:.>'.join(address) + '<STR_LIT>')<EOL>
Convert address to string :param address: WIPV4Address to convert :param dns_format: whether to use arpa-format or not :return:
f9859:c1:m4
@verify_type(address=(str, tuple, list, set), network_address=bool)<EOL><INDENT>@verify_value(address=lambda x: isinstance(x, (tuple, list, set)) is False or len(x) == <NUM_LIT:2>)<EOL>@verify_value(address=lambda x: isinstance(x, (tuple, list, set)) is False or isinstance(x[<NUM_LIT:0>], WIPV4Address))<EOL>@verify_value(address=lambda x: isinstance(x, (tuple, list, set)) is False or isinstance(x[<NUM_LIT:1>], int))<EOL>def __init__(self, address, network_address=True):<DEDENT>
if isinstance(address, str) is True:<EOL><INDENT>ip_address, self.__mask = address.strip().split(WNetworkIPV4.delimiter)<EOL>self.__address = WIPV4Address(ip_address)<EOL><DEDENT>else:<EOL><INDENT>self.__address = address[<NUM_LIT:0>]<EOL>self.__mask = address[<NUM_LIT:1>]<EOL><DEDENT>self.__mask = int(self.__mask)<EOL>if self.__mask < <NUM_LIT:0> or self.__mask > len(self.__address.bin_address()):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>' % (str(self.__mask), address)<EOL>)<EOL><DEDENT>self.__network_address__ = network_address<EOL>if network_address:<EOL><INDENT>bin_address = self.__address.bin_address()<EOL>if int(bin_address[self.__mask:]) != <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>' % (str(self.__mask), address)<EOL>)<EOL><DEDENT><DEDENT>
Construct new network address :param address: address as a string or as tuple/list/set. where the first element is WIPV4Address and \ the second one is network mask (as bits count) :param network_address: whether this object is host address with network mask or an address of a network
f9859:c2:m0
def address(self):
return self.__address<EOL>
Return IP address :return: WIPV4Address
f9859:c2:m1
def mask(self):
return self.__mask<EOL>
Return network mask (as bits count) :return: int
f9859:c2:m2
@verify_type(skip_network_address=bool)<EOL><INDENT>def first_address(self, skip_network_address=True):<DEDENT>
bin_address = self.__address.bin_address()<EOL>bin_address_length = len(bin_address)<EOL>if self.__mask > (bin_address_length - <NUM_LIT:2>):<EOL><INDENT>skip_network_address = False<EOL><DEDENT>for i in range(bin_address_length - self.__mask):<EOL><INDENT>bin_address[self.__mask + i] = <NUM_LIT:0><EOL><DEDENT>if skip_network_address:<EOL><INDENT>bin_address[bin_address_length - <NUM_LIT:1>] = <NUM_LIT:1><EOL><DEDENT>return WIPV4Address(bin_address)<EOL>
Return the first IP address of this network :param 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) :return: WIPV4Address
f9859:c2:m3
@verify_type(skip_broadcast_address=bool)<EOL><INDENT>def last_address(self, skip_broadcast_address=True):<DEDENT>
bin_address = self.__address.bin_address()<EOL>bin_address_length = len(bin_address)<EOL>if self.__mask > (bin_address_length - <NUM_LIT:2>):<EOL><INDENT>skip_broadcast_address = False<EOL><DEDENT>for i in range(bin_address_length - self.__mask):<EOL><INDENT>bin_address[self.__mask + i] = <NUM_LIT:1><EOL><DEDENT>if skip_broadcast_address:<EOL><INDENT>bin_address[bin_address_length - <NUM_LIT:1>] = <NUM_LIT:0><EOL><DEDENT>return WIPV4Address(bin_address)<EOL>
Return the last IP address of this network :param skip_broadcast_address: this flag specifies whether to skip the very last address (that is \ usually used as broadcast address) or not. :return: WIPV4Address
f9859:c2:m4
def iterator(self, skip_network_address=True, skip_broadcast_address=True):
return WNetworkIPV4Iterator(self, skip_network_address, skip_broadcast_address)<EOL>
Return iterator, that can iterate over network addresses :param skip_network_address: same as skip_network_address in :meth:`.NetworkIPV4.first_address` method :param skip_broadcast_address: same as skip_broadcast_address in :meth:`.NetworkIPV4.last_address` \ method :return: NetworkIPV4Iterator
f9859:c2:m5
@verify_type(address=WIPV4Address)<EOL><INDENT>def __contains__(self, address):<DEDENT>
int_value = int(address.bin_address())<EOL>first_address = int(self.first_address().bin_address())<EOL>last_address = int(self.last_address().bin_address())<EOL>return int_value >= first_address and int_value <= last_address<EOL>
Check if this network contains specified IP address. :param address: address to check :return: bool
f9859:c2:m6
@staticmethod<EOL><INDENT>@verify_type(address=WIPV4Address)<EOL>def is_multicast(address):<DEDENT>
return address in WNetworkIPV4('<STR_LIT>')<EOL>
Check if address is a multicast address. :param address: IP address to check :return: bool see also https://tools.ietf.org/html/rfc5771
f9859:c2:m7
@verify_type(network=(WIPV4Address, WNetworkIPV4), skip_network_address=bool, skip_broadcast_address=bool)<EOL><INDENT>def __init__(self, network, skip_network_address=True, skip_broadcast_address=True):<DEDENT>
if isinstance(network, WIPV4Address) is True:<EOL><INDENT>self.__network = WNetworkIPV4((network, len(network.bin_address())))<EOL><DEDENT>else:<EOL><INDENT>self.__network = network<EOL><DEDENT>self.__skip_network_address = skip_network_address<EOL>self.__skip_broadcast_address = skip_broadcast_address<EOL>
Create new iterator :param network: network to iterate. If it is WIPV4Address instance, then iterate over single address :param skip_network_address: same as skip_network_address in :meth:`.NetworkIPV4.first_address` method :param skip_broadcast_address: same as skip_broadcast_address in :meth:`.NetworkIPV4.last_address` \ method
f9859:c3:m0
def __iter__(self):
first_address = self.__network.first_address(skip_network_address=self.__skip_network_address)<EOL>last_address = self.__network.last_address(skip_broadcast_address=self.__skip_broadcast_address)<EOL>for i in range(int(first_address.bin_address()), int(last_address.bin_address()) + <NUM_LIT:1>):<EOL><INDENT>yield WIPV4Address(i)<EOL><DEDENT>
Iterate call :return: None
f9859:c3:m1
@verify_type(port=int)<EOL><INDENT>@verify_value(port=lambda x: WIPPort.minimum_port_number <= x <= WIPPort.maximum_port_number)<EOL>def __init__(self, port):<DEDENT>
self.__port = port<EOL>
Construct new IP port :param port: initialization value
f9859:c4:m0
def __int__(self):
return self.__port<EOL>
Return port number as int :return: int
f9859:c4:m1
def __str__(self):
return str(self.__port)<EOL>
Return port number as string :return: str
f9859:c4:m2
@verify_type(address=(str, list, tuple, set, None))<EOL><INDENT>def __init__(self, address=None):<DEDENT>
self._labels = []<EOL>if isinstance(address, str) is True:<EOL><INDENT>self._labels = WFQDN.from_string(address)._labels<EOL><DEDENT>elif isinstance(address, (list, tuple, set)) is True:<EOL><INDENT>self._labels = WFQDN.from_string('<STR_LIT:.>'.join(address))._labels<EOL><DEDENT>
Construct new FQDN. If no address is specified, then this FQDN represent root node, which is '.' :param address: FQDN address in string or in list/tuple/set of labels
f9859:c5:m0
@staticmethod<EOL><INDENT>@verify_type(address=str)<EOL>def from_string(address):<DEDENT>
if len(address) == <NUM_LIT:0>:<EOL><INDENT>return WFQDN()<EOL><DEDENT>if address[-<NUM_LIT:1>] == '<STR_LIT:.>':<EOL><INDENT>address = address[:-<NUM_LIT:1>]<EOL><DEDENT>if len(address) > WFQDN.maximum_fqdn_length:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>result = WFQDN()<EOL>for label in address.split('<STR_LIT:.>'):<EOL><INDENT>if isinstance(label, str) and WFQDN.re_label.match(label):<EOL><INDENT>result._labels.append(label)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>return result<EOL>
Convert doted-written FQDN address to WFQDN object :param address: address to convert :return: WFQDN
f9859:c5:m1
@staticmethod<EOL><INDENT>@verify_type(leading_dot=bool)<EOL>def to_string(address, leading_dot=False):<DEDENT>
if isinstance(address, WFQDN) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>result = '<STR_LIT:.>'.join(address._labels)<EOL>return result if leading_dot is False else (result + '<STR_LIT:.>')<EOL>
Return doted-written address by the given WFQDN object :param address: address to convert :param leading_dot: whether this function place leading dot to the result or not :return: str
f9859:c5:m2
def __str__(self):
return WFQDN.to_string(self)<EOL>
Return string :return: str
f9859:c5:m3
@staticmethod<EOL><INDENT>@verify_type(idn_fqdn=str)<EOL>def punycode(idn_fqdn):<DEDENT>
return WFQDN(idn_fqdn.encode('<STR_LIT>').decode('<STR_LIT:ascii>'))<EOL>
Create WFQDN from IDN (Internationalized domain name) by reverting it to punycode :param idn_fqdn: internationalized domain name to convert :return: WFQDN see also https://en.wikipedia.org/wiki/Internationalized_domain_name see also https://en.wikipedia.org/wiki/Punycode
f9859:c5:m4
@verify_type('<STR_LIT>', address=(WFQDN, WIPV4Address, str, WBinArray, int, None), port=(WIPPort, int, None))<EOL><INDENT>def __init__(self, address=None, port=None):<DEDENT>
self.__address = None<EOL>if address is not None:<EOL><INDENT>if isinstance(address, (WFQDN, WIPV4Address)) is True:<EOL><INDENT>self.__address = address<EOL><DEDENT>elif isinstance(address, (WBinArray, int)) is True:<EOL><INDENT>self.__address = WIPV4Address(address)<EOL><DEDENT>else:<EOL><INDENT>self.__address = WIPV4SocketInfo.parse_address(address)<EOL><DEDENT><DEDENT>self.__port = None<EOL>if port is not None:<EOL><INDENT>self.__port = port if isinstance(port, WIPPort) else WIPPort(port)<EOL><DEDENT>
Construct new pair :param address: associated IP address :param port: associated IP port
f9859:c6:m0
def address(self):
return self.__address<EOL>
Return associated IP address or None if not available :return: WIPV4Address or WFQDN or None
f9859:c6:m1
def port(self):
return self.__port<EOL>
Return associated IP port or None if not available :return: WIPPort or None
f9859:c6:m2
def pair(self):
address = str(self.__address) if self.__address is not None else '<STR_LIT>'<EOL>port = int(self.__port) if self.__port is not None else <NUM_LIT:0><EOL>return address, port<EOL>
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) :return: 2 value tuple of str and int.
f9859:c6:m3
@staticmethod<EOL><INDENT>@verify_type(address=str)<EOL>def parse_address(address):<DEDENT>
if len(address) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>try:<EOL><INDENT>return WIPV4Address(address)<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>return WFQDN(address)<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT>raise ValueError('<STR_LIT>')<EOL>
Parse string and return :class:`.WIPV4Address` object if an IP address is specified, :class:`.WFQDN` if domain name is specified and None if the string is empty. :param address: string to parse :return: WIPV4Address or WFQDN or None
f9859:c6:m4
@classmethod<EOL><INDENT>@verify_type(info=str)<EOL>@verify_value(info=lambda x: len(x) > <NUM_LIT:0>)<EOL>def parse_socket_info(cls, info):<DEDENT>
info = info.split('<STR_LIT::>')<EOL>if len(info) > <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>address = info[<NUM_LIT:0>].strip()<EOL>port = int(info[<NUM_LIT:1>].strip()) if len(info) == <NUM_LIT:2> else None<EOL>return WIPV4SocketInfo(address=address, port=port)<EOL>
Parse string that is formed like '[address]<:port>' and return corresponding :class:`.WIPV4ScketInfo` object :param info: string to parse :return: WIPV4ScketInfo
f9859:c6:m5
@verify_type(config=(WConfig, None), config_section=(str, None))<EOL><INDENT>def __init__(self, config=None, config_section=None):<DEDENT>
self.__configuration = WConfig()<EOL>self.__configuration.merge(os.path.join(os.path.dirname(__file__), '<STR_LIT:..>', '<STR_LIT:..>', '<STR_LIT>'))<EOL>if config is not None:<EOL><INDENT>self.__configuration.merge_section(config, '<STR_LIT>', section_from=config_section)<EOL><DEDENT>
Merge configuration to this beacon :param config: configuration storage :param config_section: configuration section name where options are
f9860:c0:m0
def config(self):
return self.__configuration<EOL>
Return beacon configuration :return: WConfig
f9860:c0:m1
@abstractmethod<EOL><INDENT>@verify_type(message=bytes, source=WIPV4SocketInfo, description=WDataDescription)<EOL>def __call__(self, message, source, description):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Method where all the magic is done. :param message: binary message (request or response) :param source: network source address (original address) :param description: defines whether message is a request or a response :return: None
f9860:c1:m0
@verify_type(config=WConfig, messanger=(WBeaconMessengerBase, None), callback=(WNetworkBeaconCallback, None))<EOL><INDENT>def __init__(self, config, messenger=None, callback=None):<DEDENT>
WNativeSocketDirectIOHandler.__init__(self)<EOL>self.__config = config<EOL>self.__messenger = messenger if messenger is not None else WBeaconMessenger()<EOL>self.__callback = callback<EOL>
Create new io-handler for beacon :param config: beacon io-configuration :param messenger: beacon messenger (or None for :class:`.WBeaconMessenger`) :param callback: beacon callback (or None if it is not required)
f9860:c2:m0
def messenger(self):
return self.__messenger<EOL>
Return beacon messenger :return: WBeaconMessenger
f9860:c2:m1
def max_size(self):
return min(self.message_maxsize, self.messenger().message_maxsize)<EOL>
Return maximum message size. (Minimum between this class 'message_maxsize' value and messengers 'message_maxsize' value) :return: int
f9860:c2:m2
def config(self):
return self.__config<EOL>
Return handler`s configuration :return: WConfig
f9860:c2:m3
def callback(self):
return self.__callback<EOL>
Return handler`s callback :return: WNetworkBeaconCallback (or None)
f9860:c2:m4
@verify_type('<STR_LIT>', io_loop=IOLoop)<EOL><INDENT>def setup_handler(self, io_loop):<DEDENT>
WNativeSocketHandler.setup_handler(self, io_loop)<EOL>if self.server_mode() is False:<EOL><INDENT>self.io_handler().transport_socket().sendto(<EOL>self.io_handler().messenger().request(self.config()),<EOL>self.transport().target_socket(self.config()).pair()<EOL>)<EOL><DEDENT>
:meth:`.WIOLoopServiceHandler.setup_handler` implementation. When this object is in 'non-server mode' (client mode), then beacon message is sent
f9860:c3:m1
@verify_type('<STR_LIT>', config=WConfig, io_handler=WBeaconIOHandler, server_mode=bool)<EOL><INDENT>@verify_type('<STR_LIT>', transport=(WNetworkNativeTransportProto, None), timeout=(int, None))<EOL>def __init__(self, config, io_handler, server_mode, transport, timeout=None):<DEDENT>
handler = WBeaconHandler(config, io_handler, server_mode, transport)<EOL>WIOLoopService.__init__(self, handler, timeout=timeout)<EOL>
Create new beacon service :param config: beacon's configuration :param io_handler: io-handler to use :param server_mode: 'server_mode' flag :param transport: beacon's transport :param timeout: same as timeout in :meth:`.WIOLoopService.__init__`
f9860:c4:m0
@verify_type('<STR_LIT>', config=(WConfig, None), config_section=(str, None))<EOL><INDENT>@verify_type('<STR_LIT>', messanger=(WBeaconMessengerBase, None), callback=(WNetworkBeaconCallback, None))<EOL>@verify_type('<STR_LIT>', process_any=bool, transport=(WNetworkNativeTransportProto, None))<EOL>def __init__(<EOL>self, config=None, config_section=None, messenger=None, callback=None, process_any=False, transport=None<EOL>):<DEDENT>
WBeaconConfig.__init__(self, config=config, config_section=config_section)<EOL>io_handler = WNetworkServerBeacon.Handler(self.config(), messenger, callback, process_any=process_any)<EOL>WNetworkBeaconBase.__init__(self, self.config(), io_handler, True, transport)<EOL>
Create new server beacon :param config: same as config in :meth:`.WBeaconConfig.__init__` :param config_section: same as config_section in :meth:`.WBeaconConfig.__init__` :param messenger: same as messenger in :meth:`.WNetworkServerBeacon.Handler.__init__` :param callback: same as callback in :meth:`.WNetworkServerBeacon.Handler.__init__` :param process_any: same as process_any in :meth:`.WNetworkServerBeacon.Handler.__init__` :param transport: same as transport in :meth:`.WNetworkBeaconBase.__init__`
f9860:c5:m0
@verify_type('<STR_LIT>', config=(WConfig, None), config_section=(str, None))<EOL><INDENT>@verify_type('<STR_LIT>', messenger=(WBeaconMessengerBase, None), callback=(WNetworkBeaconCallback, None))<EOL>@verify_type('<STR_LIT>', transport=(WNetworkNativeTransportProto, None))<EOL>def __init__(self, config=None, config_section=None, messenger=None, callback=None, transport=None):<DEDENT>
WBeaconConfig.__init__(self, config=config, config_section=config_section)<EOL>io_handler = WNetworkClientBeacon.Handler(self.config(), messenger, callback)<EOL>timeout = self.config().getint('<STR_LIT>', '<STR_LIT>')<EOL>WNetworkBeaconBase.__init__(self, self.config(), io_handler, False, transport, timeout)<EOL>
Create new client beacon :param config: same as config in :meth:`.WBeaconConfig.__init__` :param config_section: same as config_section in :meth:`.WBeaconConfig.__init__` :param messenger: same as messenger in :meth:`.WNetworkClientBeacon.Handler.__init__` :param callback: same as callback in :meth:`.WNetworkClientBeacon.Handler.__init__` :param transport: same as transport in :meth:`.WNetworkBeaconBase.__init__`
f9860:c6:m0
def __init__(self, config=None, config_section=None, thread_name=None, messenger=None):
WNetworkServerBeacon.__init__(self, config=config, config_section=config_section, messenger=messenger)<EOL>WThreadTask.__init__(self, thread_name=thread_name)<EOL>
Create new threaded task :param config: same as config in :meth:`.WNetworkServerBeacon.__init__` method :param config_section: same as config_section in :meth:`.WNetworkServerBeacon.__init__` method :param thread_name: same as thread_name in :meth:`.WThreadTask.__init__` method :param messenger: same as messenger in :meth:`.WNetworkServerBeacon.__init__` method
f9861:c0:m0
@abstractmethod<EOL><INDENT>@verify_type(beacon_config=WConfig)<EOL>def request(self, beacon_config):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Generate client request for beacon. It is calling from client side. :param beacon_config: client beacon configuration. :return: bytes
f9862:c0:m0
@abstractmethod<EOL><INDENT>@verify_type(beacon_config=WConfig, request=bytes, client_address=WIPV4SocketInfo)<EOL>def has_response(self, beacon_config, request, client_address):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Whether this messenger has response or it must skip the request. Return True if there is a response, otherwise - False. If this method returns False, then calling a :meth:`.WBeaconMessengerBase.response` method treats as error. :param beacon_config: :param request: :param client_address: :return: bool
f9862:c0:m1
@abstractmethod<EOL><INDENT>@verify_type(beacon_config=WConfig, request=bytes, client_address=WIPV4SocketInfo)<EOL>def response(self, beacon_config, request, client_address):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Generate server response for clients request. Obviously, it is calling from server side :param beacon_config: server beacon configuration :param request: client request message :param client_address: client address :return: bytes
f9862:c0:m2
@abstractmethod<EOL><INDENT>@verify_type(beacon_config=WConfig, request=bytes, client_address=WIPV4SocketInfo)<EOL>def response_address(self, beacon_config, request, client_address):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Return client address where server must send response. It is Possible, that address where server must send response is different then the origin address. In that case, client address is encoded in request message. :param beacon_config: server configuration :param request: client request message :param client_address: original client address :return: WIPV4SocketInfo
f9862:c0:m3
@abstractmethod<EOL><INDENT>@verify_type(beacon_config=WConfig, response=bytes, server_address=WIPV4SocketInfo)<EOL>def valid_response(self, beacon_config, response, server_address):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Return True if server response isn't junk. :param beacon_config: client beacon configuration :param response: server response :param server_address: original server address :return: bool
f9862:c0:m4
@verify_type('<STR_LIT>', beacon_config=WConfig)<EOL><INDENT>def request(self, beacon_config):<DEDENT>
return self.__beacon_hello_msg__<EOL>
:meth:`.WBeaconMessengerBase.request` method implementation. Sends :attr:`.WBeaconMessenger.__beacon_hello_msg__` to a server
f9862:c1:m0
@verify_type('<STR_LIT>', beacon_config=WConfig, client_address=WIPV4SocketInfo)<EOL><INDENT>@verify_type(request=bytes)<EOL>def has_response(self, beacon_config, request, client_address):<DEDENT>
return True if len(request) > <NUM_LIT:0> else False<EOL>
:meth:`.WBeaconMessengerBase.has_response` method implementation. This class has a response only if the request wasn't empty
f9862:c1:m1
@verify_type('<STR_LIT>', beacon_config=WConfig, client_address=WIPV4SocketInfo)<EOL><INDENT>@verify_type(request=bytes)<EOL>def response(self, beacon_config, request, client_address):<DEDENT>
return request<EOL>
:meth:`.WBeaconMessengerBase.response` method implementation. In response sends the same data as server has got
f9862:c1:m2
@verify_type('<STR_LIT>', beacon_config=WConfig, request=bytes)<EOL><INDENT>@verify_type(client_address=WIPV4SocketInfo)<EOL>def response_address(self, beacon_config, request, client_address):<DEDENT>
return client_address<EOL>
:meth:`.WBeaconMessengerBase.request` method implementation. Return the same address, that server detects (assume that clients address is correct)
f9862:c1:m3
@verify_type('<STR_LIT>', beacon_config=WConfig, response=bytes, server_address=WIPV4SocketInfo)<EOL><INDENT>@verify_type(response=bytes)<EOL>def valid_response(self, beacon_config, response, server_address):<DEDENT>
return True if len(response) > <NUM_LIT:0> else False<EOL>
:meth:`.WBeaconMessengerBase.valid_response` method implementation. Response is valid if it has anything.
f9862:c1:m4