
    f&                         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 Zerd Znd	 Zd
 Zd Zd Zd Zy)zAMQP Table Encoding/Decoding    N)datetime)
exceptions)PY2
basestring)unicode_typelongas_bytesc                     t        |      }t        |      }|dkD  rt        j                  |      | j	                  t        j                  d|             | j	                  |       d|z   S )zEncode 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lengths       D/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/pika/data.pyencode_short_stringr      s^     UOMF |++M::
MM&++c6*+
MM- v:    c                     t        j                  d| |      d   }|dz  }| |||z    }	 t        |      }||z  }||fS # t        $ r Y w xY w)IDecode a short string value from ``encoded`` data at ``offset``.
        r   r   r   )r   unpack_frombytesUnicodeEncodeErrorencodedoffsetr   r   s       r   decode_short_stringr"   .   sp     ##C&9!<! v/	%LE 	&f} " 		s   = 	A	A	c                     t        j                  d| |      d   }|dz  }| |||z    }	 |j                  d      }||z  }||fS # t        $ r Y w xY w)r   r   r   r   utf8)r   r   decodeUnicodeDecodeErrorr   s       r   r"   r"   ?   ss     ##C&9!<!v/	LL(E 	&f} " 		s   A 	AAc                     |xs i }t        |       }| j                  d       d}|j                         D ]#  \  }}|t        | |      z  }|t	        | |      z  }% t        j                  d|      | |<   |dz   S )zEncode 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   s         r   encode_tabler0   M   s     KREv;L
MM$I 1e(55	\&%00	1 ";;tY7F<q=r   c           
      	   t         rt        |t              r<t        |t              r|j	                  d      }| j                  t        j                  ddt        |                   | j                  |       dt        |      z   S t        |t              r_|j	                  d      }| j                  t        j                  ddt        |                   | j                  |       dt        |      z   S t        |t              rN| j                  t        j                  ddt        |                   | j                  |       dt        |      z   S t        |t              r0| j                  t        j                  ddt        |                   yt        |t              rS|d	k  r'| j                  t        j                  d
d|             y| j                  t        j                  dd|             yt        |t              r*	 t        j                  dd|      }| j                  |       yt        |t        j                        r|j!                         }|j#                         j$                  d	k  rg|j#                         j$                   }t        |t        j                  d      |z  z        }| j                  t        j                  dd||             y| j                  t        j                  ddd	t        |                   yt        |t&              rH| j                  t        j                  ddt)        j*                  |j-                                            yt        |t.              r4| j                  t        j                  dd             dt1        | |      z   S t        |t2              rtg }|D ]  }t5        ||        dj7                  |      }| j                  t        j                  ddt        |                   | j                  |       dt        |      z   S |&| j                  t        j                  dd             yt9        j:                  | |      # t        j                  $ rZ |d	k  r!t        j                  d
dt        |            }n t        j                  ddt        |            }| j                  |       Y yw xY w)zEncode 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   r      A   V)r   
isinstancer   r   encoder   r   r   r   r   boolintr   errordecimalDecimal	normalizeas_tupleexponentr   calendartimegmutctimetupledictr0   listr+   joinr   UnsupportedAMQPFieldException)r   r   packeddecimalsrawlist_piecesvalpieces           r   r+   r+   b   s    eZ(%.W-MM&++eT3u:>?MM% s5z>! eZ(LL)EMM&++eT3u:>?MM% s5z>!eU#MM&++eT3u:>?MM% s5z>!%fkk%s5z:;%19MM&++eT59:  MM&++eT59:	E3	
	[[e4FMM&! 
E7??	+!>>$$q((111Hewr2H<=>CMM&++fdHcBC  MM&++fdAs5zBC	E8	$KKtX__U5G5G5I%JK	M	E4	 fkk$-.<...	E4	  	+Cc*	+%fkk%s5z:;e3u:~	fkk$-.66vuEEI || 	qyUD$u+>UD$u+>MM&!	s   (Q. .A*SSc                     i }t        j                  d| |      d   }|dz  }||z   }||k  r)t        | |      \  }}t        | |      \  }}|||<   ||k  r)||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   s          r   decode_tabler]      sz     F""4&9!<I
aKFYE
5.)'6:V$Wf5vs 5. 6>r   c                    | ||dz    }|dz  }|dk(  r.t        j                  d| |      d   }t        |      }|dz  }||fS |dk(  r#t        j                  d| |      d   }|dz  }||fS |dk(  r#t        j                  d| |      d   }|dz  }||fS |dk(  r#t        j                  d	| |      d   }|d
z  }||fS |dk(  r#t        j                  d| |      d   }|d
z  }||fS |dk(  r#t        j                  d| |      d   }|dz  }||fS |dk(  r#t        j                  d| |      d   }|dz  }||fS |dk(  r,t        t        j                  d| |      d         }|dz  }||fS |dk(  r,t        t        j                  d| |      d         }|dz  }||fS |dk(  r,t        t        j                  d| |      d         }|dz  }||fS |dk(  r,t        t        j                  d| |      d         }|dz  }||fS |dk(  rqt        j                  d| |      d   }|dz  }t        j                  d| |      d   }|dz  }t	        j
                  |      t	        j
                  d      | z  z  }||fS |dk(  r#t        j                  d	| |      d   }|d
z  }||fS |dk(  rBt        j                  d| |      d   }|dz  }| |||z    }	 |j                  d       }||z  }||fS |d!k(  r0t        j                  d| |      d   }|dz  }| |||z    }||z  }||fS |d"k(  rUt        j                  d| |      d   }|dz  }||z   }g }||k  r&t        | |      \  }}|j                  |       ||k  r&||fS |d#k(  r6t        j                  t        j                  d| |      d         }|dz  }||fS |d$k(  rt        | |      \  }}||fS |d%k(  rd&}||fS t        j                  |      # t        $ r Y w xY w)'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   r5   z>Br      b   Bz>b   Uz>hr6      uz>Hr:   z>ir)      ir(   r7   z>q   r8   z>Q   fz>f   dz>dr<   r   r;      sr2   r$   r4   r@   r>   r?   rA   N)r   r   rD   r   rG   rH   r%   r&   rZ   r   r   utcfromtimestampr]   r   InvalidFieldTypeException)	r    r!   kindr   rT   rU   r   
offset_endrW   s	            r   rZ   rZ      s<    6&1*%D
aKF t|""4&9!<U!Z &=U 
""4&9!<!P &=K 
""4&9!<!F &=A 
""4&9!<!| &=w 
""4&9!<!r &=m 
""4&9!<!h &=c 
""4&9!<!^ &=Y 
V''gv>qAB!T &=O 
V''gv>qAB!J &=E 
V''gv>qAB!@ &={ 
V''gv>qAB!v &=q 
%%c7F;A>!  w7:!$(;hY(FGf &=_ 
""4&9!<!Z &=U 
##D'6:1=!v/	LL(E 	&D &=A 
##D'6:1=!v/&8 &=3 
##D'6:1=!f_
z!&w7KCLL z!( &= 
))tWf5a8:! &= 
&w7 &= 
 &= 22488E " 		s    O 	O)(O))__doc__r   rG   rL   r   pikar   pika.compatr   r   r   r   r	   r   r"   r0   r+   r]   rZ    r   r   <module>rp      sL    "      ' 4 4> "*PFf(r   