o
    eÃiä&  ã                   @   sš   d Z ddlZddlZddlZddlmZ ddlmZ ddlmZm	Z	 ddlm
Z
mZmZ dd„ Zer7d	d
„ Zndd
„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )zAMQP Table Encoding/Decodingé    N)Údatetime)Ú
exceptions)ÚPY2Ú
basestring)Úunicode_typeÚlongÚas_bytesc                 C   sF   t |ƒ}t|ƒ}|dkrt |¡‚|  t d|¡¡ |  |¡ d| S )zâEncode a string value as short string and append it to pieces list
    returning the size of the encoded value.

    :param list pieces: Already encoded values
    :param str value: String value to encode
    :rtype: int

    éÿ   ÚBé   )r   Úlenr   ÚShortStringTooLongÚappendÚstructÚpack)ÚpiecesÚvalueÚencoded_valueÚlength© r   úH/var/www/html/pca-backend/venv/lib/python3.10/site-packages/pika/data.pyÚencode_short_string   s   	

r   c                 C   sZ   t  d| |¡d }|d7 }| ||| … }zt|ƒ}W n	 ty$   Y nw ||7 }||fS )úIDecode a short string value from ``encoded`` data at ``offset``.
        r
   r   r   )r   Úunpack_fromÚbytesÚUnicodeEncodeError©ÚencodedÚoffsetr   r   r   r   r   Údecode_short_string.   s   ÿr   c                 C   s\   t  d| |¡d }|d7 }| ||| … }z| d¡}W n	 ty%   Y nw ||7 }||fS )r   r
   r   r   Úutf8)r   r   ÚdecodeÚUnicodeDecodeErrorr   r   r   r   r   ?   s   ÿc                 C   sd   |pi }t | ƒ}|  d¡ d}| ¡ D ]\}}|t| |ƒ7 }|t| |ƒ7 }qt d|¡| |< |d S )zÑEncode a dict as an AMQP table appending the encded table to the
    pieces list passed in.

    :param list pieces: Already encoded frame pieces
    :param dict table: The dict to encode
    :rtype: int

    Nr   ú>Ié   )r   r   Úitemsr   Úencode_valuer   r   )r   ÚtableÚlength_indexÚ	tablesizeÚkeyr   r   r   r   Úencode_tableM   s   	
r+   c              
   C   s  t r)t|tƒr(t|tƒr| d¡}|  t ddt|ƒ¡¡ |  |¡ dt|ƒ S n=t|tƒrJ| d¡}|  t ddt|ƒ¡¡ |  |¡ dt|ƒ S t|t	ƒrf|  t ddt|ƒ¡¡ |  |¡ dt|ƒ S t|t
ƒry|  t ddt|ƒ¡¡ dS t|tƒrš|d	k rŽ|  t d
d|¡¡ dS |  t dd|¡¡ dS t|tƒrÖzt dd|¡}|  |¡ W dS  tjyÕ   |d	k rÄt d
dt|ƒ¡}n	t ddt|ƒ¡}|  |¡ Y dS w t|tjƒr| ¡ }| ¡ jd	k r| ¡ j }t|t d¡|  ƒ}|  t dd||¡¡ dS |  t ddd	t|ƒ¡¡ dS t|tƒr-|  t ddt | ¡ ¡¡¡ dS t|tƒrC|  t dd¡¡ dt| |ƒ S t|tƒrrg }|D ]}t||ƒ qMd |¡}|  t ddt|ƒ¡¡ |  |¡ dt|ƒ S |du r‚|  t dd¡¡ dS t | |¡‚)zÜEncode the value passed in and append it to the pieces list returning
    the the size of the encoded value.

    :param list pieces: Already encoded values
    :param any value: The value to encode
    :rtype: int

    zutf-8z>cIó   Sé   ó   xz>cBó   té   r   z>cqó   Lz>cQó   lé	   z>ció   Ié
   z>cBió   Dé   ó   Tz>có   Fr   ó    ó   ANó   V)r   Ú
isinstancer   r   Úencoder   r   r   r   r   ÚboolÚintr   ÚerrorÚdecimalÚDecimalÚ	normalizeÚas_tupleÚexponentr   ÚcalendarÚtimegmÚutctimetupleÚdictr+   Úlistr&   Újoinr   ÚUnsupportedAMQPFieldException)r   r   ÚpackedÚdecimalsÚrawÚlist_piecesÚvalÚpiecer   r   r   r&   b   s†   




û






ÿ


úÿÿ


r&   c                 C   sb   i }t  d| |¡d }|d7 }|| }||k r-t| |ƒ\}}t| |ƒ\}}|||< ||k s||fS )a  Decode the AMQP table passed in from the encoded value returning the
    decoded result and the number of bytes read plus the offset.

    :param str encoded: The binary encoded data to decode
    :param int offset: The starting byte offset
    :rtype: tuple

    r#   r   r$   )r   r   r   Údecode_value)r   r   Úresultr)   Úlimitr*   r   r   r   r   Údecode_tableµ   s   	ýrW   c           	      C   s  | ||d … }|d7 }|dkr%t  d| |¡d }t|ƒ}|d7 }||fS |dkr:t  d| |¡d }|d7 }||fS |dkrOt  d| |¡d }|d7 }||fS |dkrdt  d	| |¡d }|d
7 }||fS |dkryt  d| |¡d }|d
7 }||fS |dkrŽt  d| |¡d }|d7 }||fS |dkr£t  d| |¡d }|d7 }||fS |dkrºtt  d| |¡d ƒ}|d7 }||fS |dkrÑtt  d| |¡d ƒ}|d7 }||fS |dkrètt  d| |¡d ƒ}|d7 }||fS |dkrÿtt  d| |¡d ƒ}|d7 }||fS |dkr/t  d| |¡d }|d7 }t  d| |¡d }|d7 }t |¡t d¡|   }||fS |dkrEt  d	| |¡d }|d
7 }||fS |dkryt  d| |¡d }|d7 }| ||| … }z| d ¡}W n
 typ   Y nw ||7 }||fS |d!kr›t  d| |¡d }|d7 }| ||| … }||7 }||fS |d"krÍt  d| |¡d }|d7 }|| }g }||k rÉt| |ƒ\}}| 	|¡ ||k s¸||fS |d#kræt
 t  d| |¡d ¡}|d7 }||fS |d$kröt| |ƒ\}}||fS |d%krd&}||fS t |¡‚)'a5  Decode the value passed in returning the decoded value and the number
    of bytes read in addition to the starting offset.

    :param str encoded: The binary encoded data to decode
    :param int offset: The starting byte offset
    :rtype: tuple
    :raises: pika.exceptions.InvalidFieldTypeException

    r   r/   z>Br   ó   bó   Bz>bó   Uz>hr0   ó   uz>Hr4   z>ir$   ó   ir#   r1   z>qé   r2   z>Qó   fz>fó   dz>dr6   r
   r5   ó   sr,   r    r.   r;   r8   r9   r<   N)r   r   r?   r   rB   rC   r!   r"   rT   r   r   ÚutcfromtimestamprW   r   ÚInvalidFieldTypeException)	r   r   Úkindr   rO   rP   r   Ú
offset_endrR   r   r   r   rT   É   sÄ   m–h›c ^¥YªT¯O´J¹E¾@Ã;
È3
Ñ-
Öÿ"
à
ç


þ
ñÿ
÷
û
þrT   )Ú__doc__r   rB   rG   r   Úpikar   Úpika.compatr   r   r   r   r   r   r   r+   r&   rW   rT   r   r   r   r   Ú<module>   s     
S