U vł¾f…$ć@sVdZddlZddlmZddlmZddlmZmZm Z ddl m Z Gdd„dƒZ dS) z& Implementation of an SSH2 "message". éN)ŚBytesIO)Śutil)Ś zero_byteŚmax_byteŚone_byte)Śuc@sžeZdZdZdZd>dd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„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„Zd:d;„Z d`. :return: the next (`bytes`) byte of the message, or ``b''`` if there aren't any bytes remaining. é)r"rr r r Śget_byteqs zMessage.get_bytecCs| d”}|tkS)z2 Fetch a boolean from the stream. r#)r"r©r r!r r r Ś 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 Śbyter r r Śget_adaptive_intƒs  zMessage.get_adaptive_intcCst d| d””dS)z/ Fetch an int from the stream. r(ér©r+r,r"rr r r Śget_intszMessage.get_intcCst d| d””dS)zj Fetch a 64-bit int from the stream. :return: a 64-bit unsigned integer (`int`). ś>Qérr0rr r r Ś get_int64•szMessage.get_int64cCst | ””S)zr Fetch a long int (mpint) from the stream. :return: an arbitrary-length integer (`int`). )rr)r*rr r r Ś get_mpintszMessage.get_mpintcCs| | ””S)zą Fetch a "string" from the stream. This will actually be a `bytes` object, and may contain unprintable characters. (It's not unheard of for a string to contain another byte-stream message.) ©r"r1rr r r Ś get_string§szMessage.get_stringcCs t| ”ƒS)zš Fetch a Unicode string from the stream. This currently operates by attempting to encode the next "string" as ``utf-8``. )rr7rr r r Śget_text±szMessage.get_textcCs| | ””S)z@ Alias for `get_string` (obtains a bytestring). r6rr r r r*ŗ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. ś,)r8Śsplitrr r r Śget_listĄszMessage.get_listcCs|j |”|S)zj Write bytes to the stream, without any formatting. :param bytes b: bytes to add ©r Śwriter%r r r Ś add_bytesČs zMessage.add_bytescCs|j |”|S)zq Write a single byte to the stream, without any formatting. :param bytes b: byte to add r<r%r r r Ś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%r r r Ś 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 r r r Śadd_intęszMessage.add_intcCs@|tjkr(|j t”| t |””n|j t  d|””|SrA) rŚbig_intr r=rŚ add_stringrŚ deflate_longr+rCrDr r r Śadd_adaptive_intļs   zMessage.add_adaptive_intcCs|j t d|””|S)zX Add a 64-bit int to the stream. :param int n: long int to add r2rBrDr r r Ś 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 int z: long int to add )rGrrH)r Śzr r r Ś add_mpintszMessage.add_mpintcCs(t |”}| t|ƒ”|j |”|S)z[ Add a bytestring to the stream. :param byte s: bytestring to add )rrrErr r=)r Śsr r r rGs  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 r9)rGŚjoin)r Ślr r r Śadd_listszMessage.add_listcCsNt|ƒtkr| |”St|tƒr*| |”St|ƒtkr@| |”S| |”SdSr) ŚtypeŚboolr@Ś isinstanceŚintrIŚlistrPrG)r Śir r r Ś_add's      z Message._addcGs|D]}| |”qdS)a Add a sequence of items to the stream. The values are encoded based on their type: bytes, str, int, bool, or list. .. warning:: Longs are encoded non-deterministically. Don't use this method. :param seq: the sequence of items N)rW)r ŚseqŚitemr r r Śadd3s z Message.add)N)"Ś__name__Ś __module__Ś __qualname__Ś__doc__rFrrrrrrrr"r$r&r.r1r4r5r7r8r*r;r>r?r@rErIrJrLrGrPrWrZr r r r rs>                    r) r^r+ŚiorZparamikorZparamiko.commonrrrZ paramiko.utilrrr r r r Śs