o
    ¹i  ã                   @   sR   d 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 )zéPython 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                 C   s   i | ]\}}||“qS © r   )Ú.0ÚidxÚcr   r   úH/var/www/edux/Edux_v2/venv/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   sn   t | ƒd rtdt | ƒ ƒ‚t | ƒd }t 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 %iú>%dIr   )Ú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>| 
|¡ q6tj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 %ir   r   )Ú
isinstanceÚstrr   ÚUnicodeEncodeErrorr   r   ÚrangeÚ	enumerater   ÚZ85MAPr   r   Úpack)Úz85bytesr   r   r	   ÚvalueÚjr   r   r   r   Údecode(   s    
ÿr)   )	Ú__doc__r   r   r#   r$   r"   r   r   r)   r   r   r   r   Ú<module>   s    