=OXc@sdZddlZddlmZddlmZmZmZmZddl m Z m Z m Z m Z defdYZdS(s& Implementation of an SSH2 "message". iN(tutil(t zero_bytetmax_bytetone_bytetasbytes(tlongtBytesIOtut integer_typestMessagecBs"eZdZedZddZdZdZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"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 |jS(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|jjdS(sP Returns a string representation of this object, for debugging. sparamiko.Message(t)(treprR tgetvalue(R ((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt__repr__>scCs |jjS(sK Return the byte stream content of this Message, as bytes. (R R(R ((s4/usr/lib/python2.7/site-packages/paramiko/message.pyRDscCs|jjddS(sk Rewind the message to the beginning as if no items had been parsed out of it yet. iN(R tseek(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. (R ttelltreadR(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`. (R RRR(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(R RtlenR(R tntbt max_pad_size((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt get_byteses "cCs |jdS(s  Return the next byte of the message, without decomposing it. This is equivalent to `get_bytes(1) `. :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.pyt get_boolean}scCsU|jd}|tkr.tj|jS||jd7}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_ints  cCstjd|jddS(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_intscCstjd|jddS(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_int64scCstj|jS(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_mpintscCs|j|jS(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_stringscCst|j|jS(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_texts cCs|j|jS(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|jjdS(s Fetch a `list` of `strings ` 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_listscCs|jj||S(sp Write bytes to the stream, without any formatting. :param str b: bytes to add (R twrite(R R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt add_bytesscCs|jj||S(sw Write a single byte to the stream, without any formatting. :param str b: byte to add (R R1(R R((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd_bytescCs-|r|jjtn|jjt|S(si Add a boolean value to the stream. :param bool b: boolean value to add (R R1RR(R R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt add_booleanscCs |jjtjd||S(s] Add an integer to the stream. :param int n: integer to add s>I(R R1R%tpack(R R((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd_intscCsX|tjkr8|jjt|jtj|n|jjtj d||S(s] Add an integer to the stream. :param int n: integer to add s>I( R tbig_intR R1Rt add_stringRt deflate_longR%R5(R R((s4/usr/lib/python2.7/site-packages/paramiko/message.pytadd_adaptive_ints cCs |jjtjd||S(sY Add a 64-bit int to the stream. :param long n: long int to add s>Q(R R1R%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 (RR6RR R1(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|tr;|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.pyts  ""