Messages Module¶
-
py2p.messages.compress(msg, method)[source]¶ Shortcut method for compression
Parameters: Returns: Defined by the compression method, but typically the bytes of the compressed message
Warning
The types fed are dependent on which compression method you use. Best to assume most values are
bytesorbytearrayRaises: ValueError– if there is an unknown compression method, or a method-specific error
-
py2p.messages.decompress(msg, method)[source]¶ Shortcut method for decompression
Parameters: Returns: Defined by the decompression method, but typically the bytes of the compressed message
Warning
The types fed are dependent on which decompression method you use. Best to assume most values are
bytesorbytearrayRaises: ValueError– if there is an unknown compression method, or a method-specific error
-
class
py2p.messages.InternalMessage(msg_type, sender, payload, compression=None, timestamp=None)[source]¶ An object used to build and parse protocol-defined message structures
-
classmethod
feed_string(string, sizeless=False, compressions=None)[source]¶ Constructs a
InternalMessagefrom a string orbytesobject.Parameters: - string – The string you wish to parse
- sizeless – A
boolwhich describes whether this string has its size header (default: it does) - compressions – A iterable containing the standardized compression
methods this message might be under
(default:
[])
Returns: A
InternalMessagefrom the given stringRaises: AttributeError– Fed a non-string, non-bytesargumentAssertionError– Initial size header is incorrectValueError– Unrecognized compression method fed in compressionsIndexError– Packet headers are incorrect OR unrecognized compression
-
__init__(msg_type, sender, payload, compression=None, timestamp=None)[source]¶ Initializes a
InternalMessageinstanceParameters: - msg_type – A header for the message you wish to send
- sender – A sender ID the message is using
- payload – An iterable of objects containing the payload of the message
- compression – A list of the compression methods this message
may use (default:
[]) - timestamp – The current UTC timestamp (as an
int) (default: result ofpy2p.utils.getUTC())
Raises: TypeError– If you feed an object which cannot be fed to msgpack
-
compression_fail¶
-
compression_used¶ Returns the compression method this message is using
-
msg_type¶
-
sender¶
-
compression¶
-
time¶
-
time_58¶ Returns this message’s timestamp in base_58
-
id¶ Returns the message id
-
classmethod