o
    Zh.                     @  s^   d Z ddlmZ ddlZdZdd eeD Zdd ed	D ddd
 Zdd Z	d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.


    )annotationsNsU   0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#c                 C  s   i | ]\}}||qS  r   ).0idxcr   r   D/var/www/html/lang_env/lib/python3.10/site-packages/zmq/utils/z85.py
<dictcomp>   s    r   c                 C  s   g | ]}d | qS )U   r   )r   ir   r   r   
<listcomp>   s    r      c                 C  sv   t | d rtdt |  t | d }td|dd| }g }|D ]}tD ]}|t|| d   q(q$t|S )zencode raw bytes into Z85   z"length must be multiple of 4, not >dIr	   )len
ValueErrorstructunpack_85sappendZ85CHARSbytes)rawbytesnvaluesvaluesencodedvoffsetr   r   r   encode   s   r    c                 C  s   t | trz| d} W n ty   tdw t| d r'tdt|  t| d }g }tdt| dD ]}d}ttD ]\}}|t	| ||   | 7 }q?|
| q7tjd|dd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 r   r   r   r   )
isinstancestrr    UnicodeEncodeErrorr   r   range	enumerater   Z85MAPr   r   pack)Zz85bytesr   r   r
   valuejr   r   r   r   decode(   s    
r+   )__doc__
__future__r   r   r   r&   r'   r%   r   r    r+   r   r   r   r   <module>   s    