
    Zd                         d Z ddlZdZd  ee          D             Zd  ed          D             ddd         Zd Zd	 ZdS )
zPython implementation of Z85 85-bit encoding

Z85 encoding is a plaintext encoding for a bytestring interpreted as 32bit integers.
Since the chunks are 32bit, a bytestring must be a multiple of 4 bytes.
See ZMQ RFC 32 for details.


    NsU   0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#c                     i | ]\  }}||	S  r   ).0idxcs      -lib/python3.11/site-packages/zmq/utils/z85.py
<dictcomp>r	      s    	3	3	3VS!!S	3	3	3    c                     g | ]}d |z  S )U   r   )r   is     r   
<listcomp>r      s       !A   r
      c                 D   t          |           dz  rt          dt          |           z            t          |           dz  }t          j        d|z  |           }g }|D ]2}t          D ](}|                    t          ||z  dz                      )3t          |          S )zencode raw bytes into Z85   z$length must be multiple of 4, not %i>%dIr   )len
ValueErrorstructunpack_85sappendZ85CHARSbytes)rawbytesnvaluesvaluesencodedvoffsets         r   encoder"      s     8}}q Q?#h--OPPP(mmaG]6G+X66FG 9 9 	9 	9FNN8Q&[B$678888	9 >>r
   c                 $   t          | t                    r4	 |                     d          } n# t          $ r t	          d          w xY wt          |           dz  rt	          dt          |           z            t          |           dz  }g }t          dt          |           d          D ]O}d}t          t                    D ]!\  }}|t          | ||z                     |z  z  }"|
                    |           Pt          j        d|z  g|R  S )z3decode Z85 bytes to raw bytes, accepts ASCII stringasciiz4string argument should contain only ASCII charactersr   z(Z85 length must be multiple of 5, not %ir   r   )
isinstancestrr"   UnicodeEncodeErrorr   r   range	enumerater   Z85MAPr   r   pack)z85bytesr   r   r   valuejr!   s          r   decoder/   (   s0   (C   U	Uw//HH! 	U 	U 	USTTT	U 8}}q UCc(mmSTTT(mmaGF1c(mmQ''  "4 	6 	6IAvVHQUO,v55EEe;v'1&1111s	   - A)	__doc__r   r   r)   r*   r(   r   r"   r/   r   r
   r   <module>r1      s      d	3	3yy22	3	3	3  uuQxx   2&  "2 2 2 2 2r
   