Implementation of an SSH2 “message”.
- class paramiko.message.Message(content=None)¶
An SSH2 message is a stream of bytes that encodes some combination of strings, integers, bools, and infinite-precision integers. This class builds or breaks down such a byte stream.
Normally you don’t need to deal with anything this low-level, but it’s exposed for people implementing custom extensions, or features that paramiko doesn’t support yet.
Create a new SSH2 message.
content (bytes) – the byte stream to use as the message content (passed in only when decomposing a message).
Returns a string representation of this object, for debugging.
list of weak references to the object (if defined)
Add a sequence of items to the stream. The values are encoded based on their type: bytes, str, int, bool, or list.
Longs are encoded non-deterministically. Don’t use this method.
seq – the sequence of items
Write a single byte to the stream, without any formatting.
b (bytes) – byte to add
Write bytes to the stream, without any formatting.
b (bytes) – bytes to add
Add a list of strings to the stream. They are encoded identically to a single string of values separated by commas. (Yes, really, that’s how SSH2 does it.)
l – list of strings to add
Add a long int to the stream, encoded as an infinite-precision integer. This method only works on positive numbers.
z (int) – long int to add
Add a bytestring to the stream.
s (byte) – bytestring to add
get_string(obtains a bytestring).
Fetch a boolean from the stream.
Return the next byte of the message, without decomposing it. This is equivalent to
the next (
bytes) byte of the message, or
b'\'if there aren’t any bytes remaining.
Return the next
nbytes of the message, without decomposing into an int, decoded string, etc. Just the raw bytes are returned. Returns a string of
nzero bytes if there weren’t
nbytes remaining in the message.
Fetch an int from the stream.
Fetch a list of
stringsfrom the stream.
These are trivially encoded as comma-separated values in a string.
bytesof this message that have been parsed and returned. The string passed into a message’s constructor can be regenerated by concatenating
Fetch a “string” from the stream. This will actually be a
bytesobject, and may contain unprintable characters. (It’s not unheard of for a string to contain another byte-stream message.)
Fetch a Unicode string from the stream.
This currently operates by attempting to encode the next “string” as
Rewind the message to the beginning as if no items had been parsed out of it yet.