Current File : //usr/lib/python2.7/site-packages/paramiko/message.pyc
�
=OXc@s�dZddlZddlmZddlmZmZmZmZddl	m
Z
mZmZm
Z
defd��YZdS(s&
Implementation of an SSH2 "message".
i����N(tutil(t	zero_bytetmax_bytetone_bytetasbytes(tlongtBytesIOtut
integer_typestMessagecBs"eZdZed�Zdd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"RS( s�
    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.
    l~cCs.|dk	rt|�|_nt�|_dS(s�
        Create a new SSH2 message.

        :param str content:
            the byte stream to use as the message content (passed in only when
            decomposing a message).
        N(tNoneRtpacket(tselftcontent((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt__init__+scCs
|j�S(sX
        Return the byte stream content of this message, as a string/bytes obj.
        (R(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt__str__8scCsdt|jj��dS(sP
        Returns a string representation of this object, for debugging.
        sparamiko.Message(t)(treprRtgetvalue(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt__repr__>scCs
|jj�S(sK
        Return the byte stream content of this Message, as bytes.
        (RR(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyRDscCs|jjd�dS(sk
        Rewind the message to the beginning as if no items had been parsed
        out of it yet.
        iN(Rtseek(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pytrewindJscCs2|jj�}|jj�}|jj|�|S(sv
        Return the bytes (as a `str`) of this message that haven't already been
        parsed and returned.
        (RttelltreadR(Rtpositiont	remainder((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt
get_remainderQscCs)|jj�}|j�|jj|�S(s�
        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`.
        (RRRR(RR((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt
get_so_far[s
cCsT|jj|�}d}t|�|ko5|knrP|t|t|�S|S(s
        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.
        iii(RRtlenR(Rtntbtmax_pad_size((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt	get_byteses
"cCs
|jd�S(s	
        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.
        i(R (R((s4/usr/lib/python2.7/site-packages/paramiko/message.pytget_byters	cCs|jd�}|tkS(s2
        Fetch a boolean from the stream.
        i(R R(RR((s4/usr/lib/python2.7/site-packages/paramiko/message.pytget_boolean}scCsU|jd�}|tkr.tj|j��S||jd�7}tjd|�dS(sZ
        Fetch an int from the stream.

        :return: a 32-bit unsigned `int`.
        iis>Ii(R RRtinflate_longt
get_binarytstructtunpack(Rtbyte((s4/usr/lib/python2.7/site-packages/paramiko/message.pytget_adaptive_int�s
cCstjd|jd��dS(sp
        Fetch an int from the stream.

        @return: a 32-bit unsigned integer.
        @rtype: int
        s>Iii(R%R&R (R((s4/usr/lib/python2.7/site-packages/paramiko/message.pytget_int�scCstjd|jd��dS(sk
        Fetch a 64-bit int from the stream.

        :return: a 64-bit unsigned integer (`long`).
        s>Qii(R%R&R (R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt	get_int64�scCstj|j��S(ss
        Fetch a long int (mpint) from the stream.

        :return: an arbitrary-length integer (`long`).
        (RR#R$(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt	get_mpint�scCs|j|j��S(s�
        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.)
        (R R)(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt
get_string�scCst|j|j���S(s
        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.)

        @return: a string.
        @rtype: string
        (RR R)(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pytget_text�s	cCs|j|j��S(s
        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.)

        @return: a string.
        @rtype: string
        (R R)(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyR$�s	cCs|j�jd�S(s�
        Fetch a `list` of `strings <str>` from the stream.
        
        These are trivially encoded as comma-separated values in a string.
        t,(R-tsplit(R((s4/usr/lib/python2.7/site-packages/paramiko/message.pytget_list�scCs|jj|�|S(sp
        Write bytes to the stream, without any formatting.
        
        :param str b: bytes to add
        (Rtwrite(RR((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt	add_bytes�scCs|jj|�|S(sw
        Write a single byte to the stream, without any formatting.
        
        :param str b: byte to add
        (RR1(RR((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd_byte�scCs-|r|jjt�n|jjt�|S(si
        Add a boolean value to the stream.
        
        :param bool b: boolean value to add
        (RR1RR(RR((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd_boolean�scCs |jjtjd|��|S(s]
        Add an integer to the stream.
        
        :param int n: integer to add
        s>I(RR1R%tpack(RR((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd_int�scCsX|tjkr8|jjt�|jtj|��n|jjtj	d|��|S(s]
        Add an integer to the stream.
        
        :param int n: integer to add
        s>I(
R	tbig_intRR1Rt
add_stringRtdeflate_longR%R5(RR((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd_adaptive_int�s
cCs |jjtjd|��|S(sY
        Add a 64-bit int to the stream.

        :param long n: long int to add
        s>Q(RR1R%R5(RR((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt	add_int64scCs|jtj|��|S(s�
        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
        (R8RR9(Rtz((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt	add_mpint
scCs3t|�}|jt|��|jj|�|S(sZ
        Add a string to the stream.
        
        :param str s: string to add
        (RR6RRR1(Rts((s4/usr/lib/python2.7/site-packages/paramiko/message.pyR8scCs|jdj|��|S(s�
        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
        R.(R8tjoin(Rtl((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd_list"scCskt|�tkr|j|�St|t�r;|j|�St|�tkrZ|j|�S|j|�SdS(N(	ttypetboolR4t
isinstanceRR:tlistRAR8(Rti((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt_add-s


cGs"x|D]}|j|�qWdS(s"
        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
        N(RG(Rtseqtitem((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd7s

N(#t__name__t
__module__t__doc__RR7R
RRRRRRRR R!R"R(R)R*R+R,R-R$R0R2R3R4R6R:R;R=R8RARGRJ(((s4/usr/lib/python2.7/site-packages/paramiko/message.pyR	s>	
					
	
	
																			
			
			
(RMR%tparamikoRtparamiko.commonRRRRtparamiko.py3compatRRRRtobjectR	(((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt<module>s
""