Package paramiko :: Module message :: Class Message
[frames] | no frames]

Class Message

source code

object --+
         |
        Message

An SSH2 message is a stream of bytes that encodes some combination of strings, integers, bools, and infinite-precision integers (known in Python as longs). 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.

Instance Methods
 
__init__(self, content=None)
Create a new SSH2 message.
source code
 
__str__(self)
Return the byte stream content of this message, as a string/bytes obj.
source code
 
__repr__(self)
Returns a string representation of this object, for debugging.
source code
 
asbytes(self)
Return the byte stream content of this Message, as bytes.
source code
 
rewind(self)
Rewind the message to the beginning as if no items had been parsed out of it yet.
source code
 
get_remainder(self)
Return the bytes (as a `str`) of this message that haven't already been parsed and returned.
source code
 
get_so_far(self)
Returns the `str` bytes of this message that have been parsed and returned.
source code
 
get_bytes(self, n)
Return the next ``n`` bytes of the message (as a `str`), without decomposing into an int, decoded string, etc.
source code
 
get_byte(self)
Return the next byte of the message, without decomposing it.
source code
 
get_boolean(self)
Fetch a boolean from the stream.
source code
 
get_int(self)
Fetch an int from the stream.
source code
int
get_size(self)
Fetch an int from the stream.
source code
 
get_int64(self)
Fetch a 64-bit int from the stream.
source code
 
get_mpint(self)
Fetch a long int (mpint) from the stream.
source code
 
get_string(self)
Fetch a `str` from the stream.
source code
string
get_text(self)
Fetch a string from the stream.
source code
string
get_binary(self)
Fetch a string from the stream.
source code
 
get_list(self)
Fetch a `list` of `strings <str>` from the stream.
source code
 
add_bytes(self, b)
Write bytes to the stream, without any formatting.
source code
 
add_byte(self, b)
Write a single byte to the stream, without any formatting.
source code
 
add_boolean(self, b)
Add a boolean value to the stream.
source code
 
add_size(self, n)
Add an integer to the stream.
source code
 
add_int(self, n)
Add an integer to the stream.
source code
 
add_int64(self, n)
Add a 64-bit int to the stream.
source code
 
add_mpint(self, z)
Add a long int to the stream, encoded as an infinite-precision integer.
source code
 
add_string(self, s)
Add a string to the stream.
source code
 
add_list(self, l)
Add a list of strings to the stream.
source code
 
add(self, *seq)
Add a sequence of items to the stream.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Variables
  big_int = 4278190080
Properties

Inherited from object: __class__

Method Details

__init__(self, content=None)
(Constructor)

source code 

Create a new SSH2 message.

:param str content:
    the byte stream to use as the message content (passed in only when
    decomposing a message).

Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

Return the byte stream content of this message, as a string/bytes obj.

Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

Returns a string representation of this object, for debugging.

Overrides: object.__repr__

get_so_far(self)

source code 

Returns the `str` bytes of this message that have been parsed and returned. The string passed into a message's constructor can be regenerated by concatenating ``get_so_far`` and `get_remainder`.

get_bytes(self, n)

source code 

Return the next ``n`` bytes of the message (as a `str`), without decomposing into an int, decoded string, etc. Just the raw bytes are returned. Returns a string of ``n`` zero bytes if there weren't ``n`` bytes remaining in the message.

get_byte(self)

source code 

Return the next byte of the message, without decomposing it.  This
is equivalent to `get_bytes(1) <get_bytes>`.

:return:
    the next (`str`) byte of the message, or ``''`` if there aren't
    any bytes remaining.

get_int(self)

source code 

Fetch an int from the stream.

:return: a 32-bit unsigned `int`.

get_size(self)

source code 

Fetch an int from the stream.

Returns: int
a 32-bit unsigned integer.

get_int64(self)

source code 

Fetch a 64-bit int from the stream.

:return: a 64-bit unsigned integer (`long`).

get_mpint(self)

source code 

Fetch a long int (mpint) from the stream.

:return: an arbitrary-length integer (`long`).

get_string(self)

source code 

Fetch a `str` from the stream. This could be a byte string and may contain unprintable characters. (It's not unheard of for a string to contain another byte-stream message.)

get_text(self)

source code 

Fetch a string from the stream. This could be a byte string and may contain unprintable characters. (It's not unheard of for a string to contain another byte-stream Message.)

Returns: string
a string.

get_binary(self)

source code 

Fetch a string from the stream. This could be a byte string and may contain unprintable characters. (It's not unheard of for a string to contain another byte-stream Message.)

Returns: string
a string.

get_list(self)

source code 

Fetch a `list` of `strings <str>` from the stream.

These are trivially encoded as comma-separated values in a string.

add_bytes(self, b)

source code 

Write bytes to the stream, without any formatting.

:param str b: bytes to add

add_byte(self, b)

source code 

Write a single byte to the stream, without any formatting.

:param str b: byte to add

add_boolean(self, b)

source code 

Add a boolean value to the stream.

:param bool b: boolean value to add

add_size(self, n)

source code 

Add an integer to the stream.

:param int n: integer to add

add_int(self, n)

source code 

Add an integer to the stream.

:param int n: integer to add

add_int64(self, n)

source code 

Add a 64-bit int to the stream.

:param long n: long int to add

add_mpint(self, z)

source code 

Add a long int to the stream, encoded as an infinite-precision integer. This method only works on positive numbers.

:param long z: long int to add

add_string(self, s)

source code 

Add a string to the stream.

:param str s: string to add

add_list(self, l)

source code 

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.)

:param list l: list of strings to add

add(self, *seq)

source code 

Add a sequence of items to the stream. The values are encoded based on their type: str, int, bool, list, or long.

.. warning:

   Longs are encoded non-deterministically.  Don't use this method.

:param seq: the sequence of items