a
    |Œ@h#  ã                   @   sž   d Z ddlZddlZddlmZ ddd„Zdd	d
„ZG dd„ dejƒZG dd„ dejƒZG dd„ dej	ƒZ	G dd„ deej
ƒZ
G dd„ deejƒZdd„ ZdS )a  Python 'uu_codec' Codec - UU content transfer encoding.

This codec de/encodes from bytes to bytes.

Written by Marc-Andre Lemburg (mal@lemburg.com). Some details were
adapted from uu.py which was written by Lance Ellinghouse and
modified by Jack Jansen and Fredrik Lundh.
é    N)ÚBytesIOÚstrictú<data>é¶  c           	      C   s”   |dksJ ‚t | ƒ}t ƒ }|j}|j}| dd¡}| dd¡}|d|d@ |f  d¡ƒ |d	ƒ}|r||t |¡ƒ |d	ƒ}q`|d
ƒ | ¡ t| ƒfS )Nr   Ú
z\núz\rzbegin %o %s
iÿ  Úasciié-   s    
end
)	r   ÚreadÚwriteÚreplaceÚencodeÚbinasciiZb2a_uuÚgetvalueÚlen)	ÚinputÚerrorsÚfilenameÚmodeÚinfileÚoutfiler
   r   Úchunk© r   ú#lib/python3.9/encodings/uu_codec.pyÚ	uu_encode   s    
r   c           
   
   C   sê   |dksJ ‚t | ƒ}t ƒ }|j}|j}|ƒ }|s8tdƒ‚|d d… dkr&qLq&|ƒ }|rÎ|dkr`qÎzt |¡}W nT tjyÂ } z:|d d d@ d	 d d
 }	t |d |	… ¡}W Y d }~n
d }~0 0 ||ƒ qL|sÚtdƒ‚| ¡ t| ƒfS )Nr   z"Missing "begin" line in input dataé   s   begins   end
r   é    é?   é   é   zTruncated input data)	r   Úreadliner   Ú
ValueErrorr   Za2b_uuÚErrorr   r   )
r   r   r   r   r    r   ÚsÚdataÚvÚnbytesr   r   r   Ú	uu_decode%   s,    (
r'   c                   @   s    e Zd Zddd„Zddd„ZdS )	ÚCodecr   c                 C   s
   t ||ƒS ©N)r   ©Úselfr   r   r   r   r   r   G   s    zCodec.encodec                 C   s
   t ||ƒS r)   )r'   r*   r   r   r   ÚdecodeJ   s    zCodec.decodeN)r   )r   )Ú__name__Ú
__module__Ú__qualname__r   r,   r   r   r   r   r(   F   s   
r(   c                   @   s   e Zd Zddd„ZdS )ÚIncrementalEncoderFc                 C   s   t || jƒd S ©Nr   )r   r   ©r+   r   Úfinalr   r   r   r   N   s    zIncrementalEncoder.encodeN)F)r-   r.   r/   r   r   r   r   r   r0   M   s   r0   c                   @   s   e Zd Zddd„ZdS )ÚIncrementalDecoderFc                 C   s   t || jƒd S r1   )r'   r   r2   r   r   r   r,   R   s    zIncrementalDecoder.decodeN)F)r-   r.   r/   r,   r   r   r   r   r4   Q   s   r4   c                   @   s   e Zd ZeZdS )ÚStreamWriterN©r-   r.   r/   ÚbytesÚcharbuffertyper   r   r   r   r5   U   s   r5   c                   @   s   e Zd ZeZdS )ÚStreamReaderNr6   r   r   r   r   r9   X   s   r9   c                
   C   s   t jdttttttdd�S )NÚuuF)Únamer   r,   ÚincrementalencoderÚincrementaldecoderÚstreamreaderÚstreamwriterÚ_is_text_encoding)ÚcodecsÚ	CodecInfor   r'   r0   r4   r9   r5   r   r   r   r   Úgetregentry]   s    ørC   )r   r   r   )r   )Ú__doc__rA   r   Úior   r   r'   r(   r0   r4   r5   r9   rC   r   r   r   r   Ú<module>   s   	

!