ó =OXc@s€dZddlZddlmZddlmZmZmZmZddl m Z m Z m 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„Z d„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)(treprR tgetvalue(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. (R R(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(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 |jdƒS(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|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_intscCstjd|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 ` 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 (R twrite(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 (R R1(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 (R R1RR(R R((s4/usr/lib/python2.7/site-packages/paramiko/message.pyt add_booleanâscCs |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_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_intR R1Rt 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(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|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.pyts  ""