Package paramiko :: 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
string
__repr__(self)
Returns a string representation of this object, for debugging.
source code
string
__str__(self)
Return the byte stream content of this Message, as a string.
source code
 
add(self, *seq)
Add a sequence of items to the stream.
source code
 
add_boolean(self, b)
Add a boolean value to the stream.
source code
 
add_byte(self, b)
Write a single byte to the stream, without any formatting.
source code
 
add_bytes(self, b)
Write bytes to the stream, without any formatting.
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_list(self, l)
Add a list of strings 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
bool
get_boolean(self)
Fetch a boolean from the stream.
source code
string
get_byte(self)
Return the next byte of the Message, without decomposing it.
source code
string
get_bytes(self, n)
Return the next n bytes of the Message, without decomposing into an int, string, etc.
source code
int
get_int(self)
Fetch an int from the stream.
source code
long
get_int64(self)
Fetch a 64-bit int from the stream.
source code
list of strings
get_list(self)
Fetch a list of strings from the stream.
source code
long
get_mpint(self)
Fetch a long int (mpint) from the stream.
source code
string
get_remainder(self)
Return the bytes of this Message that haven't already been parsed and returned.
source code
string
get_so_far(self)
Returns the bytes of this Message that have been parsed and returned.
source code
string
get_string(self)
Fetch a string from the stream.
source code
 
rewind(self)
Rewind the message to the beginning as if no items had been parsed out of it yet.
source code

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

Properties

Inherited from object: __class__

Method Details

__init__(self, content=None)
(Constructor)

source code 

Create a new SSH2 Message.

Parameters:
  • content (string) - the byte stream to use as the Message content (passed in only when decomposing a Message).
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

Returns a string representation of this object, for debugging.

Returns: string
Overrides: object.__repr__

__str__(self)
(Informal representation operator)

source code 

Return the byte stream content of this Message, as a string.

Returns: string
the contents of this Message.
Overrides: object.__str__

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.

Parameters:
  • seq (sequence) - the sequence of items

Bug: longs are encoded non-deterministically. Don't use this method.

add_boolean(self, b)

source code 

Add a boolean value to the stream.

Parameters:
  • b (bool) - boolean value to add

add_byte(self, b)

source code 

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

Parameters:
  • b (str) - byte to add

add_bytes(self, b)

source code 

Write bytes to the stream, without any formatting.

Parameters:
  • b (str) - bytes to add

add_int(self, n)

source code 

Add an integer to the stream.

Parameters:
  • n (int) - integer to add

add_int64(self, n)

source code 

Add a 64-bit int to the stream.

Parameters:
  • n (long) - long int 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.)

Parameters:
  • l (list(str)) - list of strings 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.

Parameters:
  • z (long) - long int to add

add_string(self, s)

source code 

Add a string to the stream.

Parameters:
  • s (str) - string to add

get_boolean(self)

source code 

Fetch a boolean from the stream.

Returns: bool
True or False (from the Message).

get_byte(self)

source code 

Return the next byte of the Message, without decomposing it. This is equivalent to get_bytes(1).

Returns: string
the next byte of the Message, or '' if there aren't any bytes remaining.

get_bytes(self, n)

source code 

Return the next n bytes of the Message, without decomposing into an int, string, etc. Just the raw bytes are returned.

Returns: string
a string of the next n bytes of the Message, or a string of n zero bytes, if there aren't n bytes remaining.

get_int(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.

Returns: long
a 64-bit unsigned integer.

get_list(self)

source code 

Fetch a list of strings from the stream. These are trivially encoded as comma-separated values in a string.

Returns: list of strings
a list of strings.

get_mpint(self)

source code 

Fetch a long int (mpint) from the stream.

Returns: long
an arbitrary-length integer.

get_remainder(self)

source code 

Return the bytes of this Message that haven't already been parsed and returned.

Returns: string
a string of the bytes not parsed yet.

get_so_far(self)

source code 

Returns the 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.

Returns: string
a string of the bytes parsed so far.

get_string(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.