Ñò
ðgcJc           @   sH   d  Z  d d k Z d d k Z d d k l Z d e f d „  ƒ  YZ d S(   s&   
Implementation of an SSH2 "message".
iÿÿÿÿN(   t   utilt   Messagec           B   sé   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s£  
    An SSH2 I{Message} is a stream of bytes that encodes some combination of
    strings, integers, bools, and infinite-precision integers (known in python
    as I{long}s).  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.
    c         C   s6   | d j o t i | ƒ |  _ n t i ƒ  |  _ d S(   sÊ   
        Create a new SSH2 Message.

        @param content: the byte stream to use as the Message content (passed
            in only when decomposing a Message).
        @type content: string
        N(   t   Nonet	   cStringIOt   StringIOt   packet(   t   selft   content(    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   __init__(   s    c         C   s   |  i  i ƒ  S(   s•   
        Return the byte stream content of this Message, as a string.

        @return: the contents of this Message.
        @rtype: string
        (   R   t   getvalue(   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   __str__5   s    c         C   s   d t  |  i i ƒ  ƒ d S(   sh   
        Returns a string representation of this object, for debugging.

        @rtype: string
        s   paramiko.Message(t   )(   t   reprR   R	   (   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   __repr__>   s    c         C   s   |  i  i d ƒ d S(   sk   
        Rewind the message to the beginning as if no items had been parsed
        out of it yet.
        i    N(   R   t   seek(   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   rewindF   s    c         C   s2   |  i  i ƒ  } |  i  i ƒ  } |  i  i | ƒ | S(   s¸   
        Return the bytes of this Message that haven't already been parsed and
        returned.

        @return: a string of the bytes not parsed yet.
        @rtype: string
        (   R   t   tellt   readR   (   R   t   positiont	   remainder(    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   get_remainderM   s    c         C   s)   |  i  i ƒ  } |  i ƒ  |  i  i | ƒ S(   s,  
        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 C{get_so_far} and L{get_remainder}.

        @return: a string of the bytes parsed so far.
        @rtype: string
        (   R   R   R   R   (   R   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt
   get_so_farZ   s    	
c         C   s@   |  i  i | ƒ } t | ƒ | j  o | d | t | ƒ S| S(   s?  
        Return the next C{n} bytes of the Message, without decomposing into
        an int, string, etc.  Just the raw bytes are returned.

        @return: a string of the next C{n} bytes of the Message, or a string
            of C{n} zero bytes, if there aren't C{n} bytes remaining.
        @rtype: string
        t    (   R   R   t   len(   R   t   nt   b(    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt	   get_bytesg   s    	c         C   s   |  i  d ƒ S(   s  
        Return the next byte of the Message, without decomposing it.  This
        is equivalent to L{get_bytes(1)<get_bytes>}.

        @return: the next byte of the Message, or C{' '} if there aren't
            any bytes remaining.
        @rtype: string
        i   (   R   (   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   get_byteu   s    	c         C   s   |  i  d ƒ } | d j S(   s   
        Fetch a boolean from the stream.

        @return: C{True} or C{False} (from the Message).
        @rtype: bool
        i   R   (   R   (   R   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   get_boolean€   s    c         C   s   t  i d |  i d ƒ ƒ d S(   sp   
        Fetch an int from the stream.

        @return: a 32-bit unsigned integer.
        @rtype: int
        s   >Ii   i    (   t   structt   unpackR   (   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   get_intŠ   s    c         C   s   t  i d |  i d ƒ ƒ d S(   sw   
        Fetch a 64-bit int from the stream.

        @return: a 64-bit unsigned integer.
        @rtype: long
        s   >Qi   i    (   R   R   R   (   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt	   get_int64“   s    c         C   s   t  i |  i ƒ  ƒ S(   s   
        Fetch a long int (mpint) from the stream.

        @return: an arbitrary-length integer.
        @rtype: long
        (   R    t   inflate_longt
   get_string(   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt	   get_mpintœ   s    c         C   s   |  i  |  i ƒ  ƒ 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   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyR"   ¥   s    	c         C   s   |  i  ƒ  i d ƒ S(   sË   
        Fetch a list of strings from the stream.  These are trivially encoded
        as comma-separated values in a string.

        @return: a list of strings.
        @rtype: list of strings
        t   ,(   R"   t   split(   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   get_list°   s    c         C   s   |  i  i | ƒ |  S(   s   
        Write bytes to the stream, without any formatting.
        
        @param b: bytes to add
        @type b: str
        (   R   t   write(   R   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt	   add_bytesº   s    c         C   s   |  i  i | ƒ |  S(   sˆ   
        Write a single byte to the stream, without any formatting.
        
        @param b: byte to add
        @type b: str
        (   R   R'   (   R   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   add_byteÄ   s    c         C   s)   | o |  i  d ƒ n |  i  d ƒ |  S(   sz   
        Add a boolean value to the stream.
        
        @param b: boolean value to add
        @type b: bool
        s   R   (   R)   (   R   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   add_booleanÎ   s    c         C   s    |  i  i t i d | ƒ ƒ |  S(   sn   
        Add an integer to the stream.
        
        @param n: integer to add
        @type n: int
        s   >I(   R   R'   R   t   pack(   R   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   add_intÛ   s    c         C   s    |  i  i t i d | ƒ ƒ |  S(   sj   
        Add a 64-bit int to the stream.

        @param n: long int to add
        @type n: long
        s   >Q(   R   R'   R   R+   (   R   R   (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt	   add_int64å   s    c         C   s   |  i  t i | ƒ ƒ |  S(   sÏ   
        Add a long int to the stream, encoded as an infinite-precision
        integer.  This method only works on positive numbers.
        
        @param z: long int to add
        @type z: long
        (   t
   add_stringR    t   deflate_long(   R   t   z(    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt	   add_mpintï   s    c         C   s'   |  i  t | ƒ ƒ |  i i | ƒ |  S(   sk   
        Add a string to the stream.
        
        @param s: string to add
        @type s: str
        (   R,   R   R   R'   (   R   t   s(    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyR.   ú   s    c         C   s   |  i  d i | ƒ ƒ |  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 l: list of strings to add
        @type l: list(str)
        R$   (   R.   t   join(   R   t   l(    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   add_list  s    	c         C   sÓ   t  | ƒ t j o |  i | ƒ St  | ƒ t j o |  i | ƒ St  | ƒ t j o, | d j o |  i | ƒ S|  i | ƒ SnO t  | ƒ t j o |  i | ƒ St  | ƒ t	 j o |  i
 | ƒ St d ƒ ‚ d  S(   Nl   ÿÿ s   Unknown type(   t   typet   strR.   t   intR,   t   longR1   t   boolR*   t   listR5   t	   Exception(   R   t   i(    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   _add  s    c         G   s"   x | D] } |  i  | ƒ q Wd S(   s3  
        Add a sequence of items to the stream.  The values are encoded based
        on their type: str, int, bool, list, or long.
        
        @param seq: the sequence of items
        @type seq: sequence
        
        @bug: longs are encoded non-deterministically.  Don't use this method.
        N(   R>   (   R   t   seqt   item(    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   add"  s    
 N(   t   __name__t
   __module__t   __doc__R   R   R
   R   R   R   R   R   R   R   R   R    R#   R"   R&   R(   R)   R*   R,   R-   R1   R.   R5   R>   RA   (    (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyR      s2   										
								
	
	
		
	
				(   RD   R   R   t   paramikoR    t   objectR   (    (    (    sO   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\message.pyt   <module>   s   