a °…bD#ć@s\dZddlZddlmZddlmZmZmZmZddl m Z m Z m Z m Z Gdd„deƒZdS)z& Implementation of an SSH2 "message". éN)Śutil)Ś zero_byteŚmax_byteŚone_byteŚasbytes)ŚlongŚBytesIOŚuŚ integer_typesc@seZdZdZedƒZd>dd„Zdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„Z d:d;„Z!dszMessage.__repr__cCs |j ”S)zK Return the byte stream content of this Message, as bytes. )r rrrrrrDszMessage.asbytescCs|j d”dS)zk Rewind the message to the beginning as if no items had been parsed out of it yet. rN)r ŚseekrrrrŚrewindJszMessage.rewindcCs$|j ”}|j ”}|j |”|S)zv Return the bytes (as a `str`) of this message that haven't already been parsed and returned. )r ŚtellŚreadr)r ŚpositionŚ remainderrrrŚ get_remainderQs   zMessage.get_remaindercCs|j ”}| ”|j |”S)zä 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 rrrrŚ get_so_far[s zMessage.get_so_farcCsD|j |”}d}t|ƒ|kr(|kr@nn|t|t|ƒS|S)a 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. i)r rŚlenr)r ŚnŚbZ max_pad_sizerrrŚ get_byteses  zMessage.get_bytescCs | d”S)a  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. é)r#rrrrŚget_byters zMessage.get_bytecCs| d”}|tkS)z2 Fetch a boolean from the stream. r$)r#r©r r"rrrŚ get_boolean}s zMessage.get_booleancCs>| d”}|tkr t | ””S|| d”7}t d|”dS)zZ Fetch an int from the stream. :return: a 32-bit unsigned `int`. r$éś>Ir)r#rrŚ inflate_longŚ get_binaryŚstructŚunpack)r ŚbyterrrŚget_adaptive_int„s  zMessage.get_adaptive_intcCst d| d””dS)z/ Fetch an int from the stream. r)ér©r,r-r#rrrrŚget_intszMessage.get_intcCst d| d””dS)zk Fetch a 64-bit int from the stream. :return: a 64-bit unsigned integer (`long`). ś>Qérr1rrrrŚ get_int64–szMessage.get_int64cCst | ””S)zs Fetch a long int (mpint) from the stream. :return: an arbitrary-length integer (`long`). )rr*r+rrrrŚ get_mpintžszMessage.get_mpintcCs| | ””S)zŃ 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#r2rrrrŚ get_string¦szMessage.get_stringcCs t| ”ƒS)z9 Fetch a Unicode string from the stream. )r r8rrrrŚget_text®szMessage.get_textcCs| | ””S)zŅ 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.) r7rrrrr+“szMessage.get_binarycCs| ” d”S)zŽ Fetch a list of `strings ` from the stream. These are trivially encoded as comma-separated values in a string. ś,)r9ŚsplitrrrrŚget_list¼szMessage.get_listcCs|j |”|S)zh Write bytes to the stream, without any formatting. :param str b: bytes to add ©r Śwriter&rrrŚ add_bytesÄs zMessage.add_bytescCs|j |”|S)zo Write a single byte to the stream, without any formatting. :param str b: byte to add r=r&rrrŚadd_byteĶs zMessage.add_bytecCs"|r|j t”n |j t”|S)za Add a boolean value to the stream. :param bool b: boolean value to add )r r>rrr&rrrŚ add_booleanÖs zMessage.add_booleancCs|j t d|””|S©zU Add an integer to the stream. :param int n: integer to add r)©r r>r,Śpack©r r!rrrŚadd_intāszMessage.add_intcCs@|tjkr(|j t”| t |””n|j t  d|””|SrB) r Śbig_intr r>rŚ add_stringrŚ deflate_longr,rDrErrrŚadd_adaptive_intės   zMessage.add_adaptive_intcCs|j t d|””|S)zY Add a 64-bit int to the stream. :param long n: long int to add r3rCrErrrŚ add_int64ųszMessage.add_int64cCs| t |””|S)z¶ 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 )rHrrI)r ŚzrrrŚ add_mpintszMessage.add_mpintcCs&t|ƒ}| t|ƒ”|j |”|S)zR Add a string to the stream. :param str s: string to add )rrFr r r>)r ŚsrrrrH s zMessage.add_stringcCs| d |””|S)zé 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 r:)rHŚjoin)r ŚlrrrŚadd_listszMessage.add_listcCsNt|ƒtur| |”St|tƒr*| |”St|ƒtur@| |”S| |”SdS)N) ŚtypeŚboolrAŚ isinstancer rJŚlistrQrH)r ŚirrrŚ_add!s      z Message._addcGs|D]}| |”qdS)a 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)rW)r ŚseqŚitemrrrŚadd+s z Message.add)N)#Ś__name__Ś __module__Ś __qualname__Ś__doc__rrGrrrrrrrr#r%r'r/r2r5r6r8r9r+r<r?r@rArFrJrKrMrHrQrWrZrrrrr s>                 r )r^r,ZparamikorZparamiko.commonrrrrZparamiko.py3compatrrr r Śobjectr rrrrŚs