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
bytes
orbytearray
Raises: 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
bytes
orbytearray
Raises: 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
InternalMessage
from a string orbytes
object.Parameters: - string – The string you wish to parse
- sizeless – A
bool
which 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
InternalMessage
from the given stringRaises: AttributeError
– Fed a non-string, non-bytes
argumentAssertionError
– 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
InternalMessage
instanceParameters: - 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