U
    `#                     @   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t 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
)
AssertionErrorr   readwritereplaceencodebinasciiZb2a_uugetvaluelen)	inputerrorsfilenamemodeinfileoutfiler   r   chunk r   (/usr/lib/python3.8/encodings/uu_codec.py	uu_encode   s    
r   c           
   
   C   s   |dkst t| }t }|j}|j}| }|s8td|d d dkr&qLq&| }|r|dkr`qzt|}W nR tjk
r } z2|d d d@ d	 d d
 }	t|d |	 }W 5 d }~X Y nX || qL|std| t	| fS )Nr   z"Missing "begin" line in input data   s   begins   end
r       ?         zTruncated input data)
r
   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/   r0   r   r   r   r   r   r1   M   s   r1   c                   @   s   e Zd ZdddZdS )IncrementalDecoderFc                 C   s   t || jd S r2   )r(   r   r3   r   r   r   r-   R   s    zIncrementalDecoder.decodeN)F)r.   r/   r0   r-   r   r   r   r   r5   Q   s   r5   c                   @   s   e Zd ZeZdS )StreamWriterNr.   r/   r0   bytescharbuffertyper   r   r   r   r6   U   s   r6   c                   @   s   e Zd ZeZdS )StreamReaderNr7   r   r   r   r   r:   X   s   r:   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(   r1   r5   r:   r6   r   r   r   r   getregentry]   s    rD   )r   r   r   )r   )__doc__rB   r   ior   r   r(   r)   r1   r5   r6   r:   rD   r   r   r   r   <module>   s   	

!