
    oh$                     \    d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 ddl
mZ  G d d      Zy)	z&
Implementation of an SSH2 "message".
    N)BytesIO)util)	zero_bytemax_byteone_byte)uc                       e Zd Zd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d Zd Zd Zd Z d  Z!y)"Messagea~  
    An SSH2 message is a stream of bytes that encodes some combination of
    strings, integers, bools, and infinite-precision integers.  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      ~ Nc                 H    |t        |      | _        yt               | _        y)z
        Create a new SSH2 message.

        :param bytes content:
            the byte stream to use as the message content (passed in only when
            decomposing a message).
        N)r   packet)selfcontents     b/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/paramiko/message.py__init__zMessage.__init__,   s     !'*DK!)DK    c                 "    | j                         S N)asbytesr   s    r   	__bytes__zMessage.__bytes__9   s    ||~r   c                 T    dt        | j                  j                               z   dz   S )zP
        Returns a string representation of this object, for debugging.
        zparamiko.Message())reprr   getvaluer   s    r   __repr__zMessage.__repr__<   s&     #T$++*>*>*@%AACGGr   c                 6    | j                   j                         S )zO
        Return the byte stream content of this Message, as a `bytes`.
        )r   r   r   s    r   r   zMessage.asbytesC   s     {{##%%r   c                 :    | j                   j                  d       y)zk
        Rewind the message to the beginning as if no items had been parsed
        out of it yet.
        r   N)r   seekr   s    r   rewindzMessage.rewindI   s    
 	r   c                     | j                   j                         }| j                   j                         }| j                   j                  |       |S )zk
        Return the `bytes` of this message that haven't already been parsed and
        returned.
        )r   tellreadr   )r   position	remainders      r   get_remainderzMessage.get_remainderP   s@    
 ;;##%KK$$&	"r   c                     | j                   j                         }| j                          | j                   j                  |      S )z
        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 ``get_so_far`` and `get_remainder`.
        )r   r!   r   r"   )r   r#   s     r   
get_so_farzMessage.get_so_farZ   s4     ;;##%{{))r   c                     | j                   j                  |      }d}t        |      |cxk  r|k  rn |S |t        |t        |      z
  z  z   S |S )a	  
        Return the next ``n`` bytes of the message, 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bmax_pad_sizes       r   	get_byteszMessage.get_bytesd   sR     KKQq6A$$ yAAJ///r   c                 $    | j                  d      S )a  
        Return the next byte of the message, without decomposing it.  This
        is equivalent to `get_bytes(1) <get_bytes>`.

        :return:
            the next (`bytes`) byte of the message, or ``b' '`` if there
            aren't any bytes remaining.
           )r-   r   s    r   get_bytezMessage.get_byteq   s     ~~a  r   c                 6    | j                  d      }|t        k7  S )z2
        Fetch a boolean from the stream.
        r/   )r-   r   r   r+   s     r   get_booleanzMessage.get_boolean|   s     NN1I~r   c                     | j                  d      }|t        k(  r#t        j                  | j	                               S || j                  d      z  }t        j                  d|      d   S )zZ
        Fetch an int from the stream.

        :return: a 32-bit unsigned `int`.
        r/      >Ir   )r-   r   r   inflate_long
get_binarystructunpack)r   bytes     r   get_adaptive_intzMessage.get_adaptive_int   s[     ~~a 8$$T__%677q!!}}T4(++r   c                 R    t        j                  d| j                  d            d   S )z/
        Fetch an int from the stream.
        r6      r   r9   r:   r-   r   s    r   get_intzMessage.get_int   s#     }}T4>>!#45a88r   c                 R    t        j                  d| j                  d            d   S )zj
        Fetch a 64-bit int from the stream.

        :return: a 64-bit unsigned integer (`int`).
        >Q   r   r?   r   s    r   	get_int64zMessage.get_int64   s#     }}T4>>!#45a88r   c                 H    t        j                  | j                               S )zr
        Fetch a long int (mpint) from the stream.

        :return: an arbitrary-length integer (`int`).
        )r   r7   r8   r   s    r   	get_mpintzMessage.get_mpint   s       !233r   c                 @    | j                  | j                               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-   r@   r   s    r   
get_stringzMessage.get_string   s     ~~dlln--r   c                 4    t        | j                               S )z
        Fetch a Unicode string from the stream.

        This currently operates by attempting to encode the next "string" as
        ``utf-8``.
        )r   rI   r   s    r   get_textzMessage.get_text   s     "##r   c                 @    | j                  | j                               S )z@
        Alias for `get_string` (obtains a bytestring).
        rH   r   s    r   r8   zMessage.get_binary   s     ~~dlln--r   c                 @    | j                         j                  d      S )z
        Fetch a list of `strings <str>` from the stream.

        These are trivially encoded as comma-separated values in a string.
        ,)rK   splitr   s    r   get_listzMessage.get_list   s     }}$$S))r   c                 <    | j                   j                  |       | S )zj
        Write bytes to the stream, without any formatting.

        :param bytes b: bytes to add
        r   writer2   s     r   	add_byteszMessage.add_bytes        	!r   c                 <    | j                   j                  |       | S )zq
        Write a single byte to the stream, without any formatting.

        :param bytes b: byte to add
        rR   r2   s     r   add_bytezMessage.add_byte   rU   r   c                     |r!| j                   j                  t               | S | j                   j                  t               | S )za
        Add a boolean value to the stream.

        :param bool b: boolean value to add
        )r   rS   r   r   r2   s     r   add_booleanzMessage.add_boolean   s9     KKh'  KKi(r   c                 d    | j                   j                  t        j                  d|             | S zU
        Add an integer to the stream.

        :param int n: integer to add
        r6   r   rS   r9   packr   r*   s     r   add_intzMessage.add_int   &     	&++dA./r   c                    |t         j                  k\  rE| j                  j                  t               | j                  t        j                  |             | S | j                  j                  t        j                  d|             | S r[   )
r
   big_intr   rS   r   
add_stringr   deflate_longr9   r]   r^   s     r   add_adaptive_intzMessage.add_adaptive_int   sd     KKh'OOD--a01  KKfkk$23r   c                 d    | j                   j                  t        j                  d|             | S )zX
        Add a 64-bit int to the stream.

        :param int n: long int to add
        rB   r\   r^   s     r   	add_int64zMessage.add_int64   r`   r   c                 N    | j                  t        j                  |             | 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
        )rc   r   rd   )r   zs     r   	add_mpintzMessage.add_mpint  s      	))!,-r   c                     t        j                  |      }| j                  t        |             | j                  j                  |       | S )z[
        Add a bytestring to the stream.

        :param byte s: bytestring to add
        )r   r   r_   r)   r   rS   )r   ss     r   rc   zMessage.add_string  s8     LLOSV!r   c                 F    | j                  dj                  |             | 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
        rN   )rc   join)r   ls     r   add_listzMessage.add_list  s     	$r   c                     t        |      t        u r| j                  |      S t        |t              r| j                  |      S t        |      t        u r| j                  |      S | j                  |      S r   )	typeboolrY   
isinstanceintre   listrp   rc   )r   is     r   _addzMessage._add'  sb    7d?##A&&3((++!W_==##??1%%r   c                 4    |D ]  }| j                  |        y)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)rx   )r   seqitems      r   addzMessage.add3  s      	DIIdO	r   r   )"__name__
__module____qualname____doc__rb   r   r   r   r   r   r%   r'   r-   r0   r3   r<   r@   rD   rF   rI   rK   r8   rP   rT   rW   rY   r_   re   rg   rj   rc   rp   rx   r|    r   r   r
   r
      s     G$H&*	!
,994.$.*
		&r   r
   )r   r9   ior   paramikor   paramiko.commonr   r   r   paramiko.utilr   r
   r   r   r   <module>r      s*   &    9 9 _ _r   