o
    Ƌ|c/                     @   sl   d Z ddlZddlZddlZg dZG dd deZddddd	Zdd
dZdd Z	e
dkr4e	  dS dS )zImplementation of the UUencode and UUdecode functions.

encode(in_file, out_file [,name, mode], *, backtick=False)
decode(in_file [, out_file, mode, quiet])
    N)Errorencodedecodec                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r     /home/conda/feedstock_root/build_artifacts/python-split_1669104742391/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/python3.10/uu.pyr   '   s    r   Fbacktickc             	   C   sx  g }z| dkrt jj} n/t| tr;|du rtj| }|du r1zt| j	}W n	 t
y0   Y nw t| d} ||  |dkrDt jj}nt|trSt|d}|| |du rYd}|du r_d}|dd}|dd	}|d
|d@ |f d | d}t|dkr|tj||d | d}t|dks|r|d n|d W |D ]}|  qdS |D ]}|  qw )zUuencode file-Nrbwbi  
z\nz\rzbegin %o %s
i  ascii-   r   r
   s   `
end
s    
end
)sysstdinbuffer
isinstancestrospathbasenamestatst_modeAttributeErroropenappendstdoutreplacewriter   readlenbinasciiZb2a_uuclose)in_fileout_filenamemoder   opened_filesdatafr   r   r	   r   *   sR   












r   c              
   C   s  g }| dkrt jj} nt| trt| d} ||  z	 |  }|s&td|	ds,q|
dd}t|dkrQ|d	 dkrQz	t|d
 d W n
 tyP   Y nw q|du rl|d dd}tj|rltd| |du rwt|d
 d}|dkrt jj}nt|trt|d}t|| |}|| |  }|r|ddkrzt|}	W n4 tjy }
 z'|d	 d d@ d d d }t|d| }	|st jd|
  W Y d}
~
nd}
~
ww ||	 |  }|r|ddks|stdW |D ]}|  qdS |D ]}|  qw )zDecode uuencoded filer   r   Tz'No valid begin line found in input files   begin          r         Ns    	
r   z"Cannot overwrite existing file: %sr   s   end    ?         zWarning: %s
zTruncated input file)r   r   r   r   r   r   r   readliner   
startswithsplitr$   int
ValueErrorrstripr   r   r   existsr    chmodstripr%   Za2b_uustderrr"   r&   )r'   r(   r*   quietr+   ZhdrZ	hdrfieldsfpsr,   vnbytesr-   r   r   r	   r   d   sr   










r   c                  C   s2  ddl } | jdd}|jddddd	d
d |jddddd	d
d | \}}t|dkr6|d td tjj	}tj
j	}t|dkrH|d }t|dkrR|d }|jrw|jrpt|trct|d}nttjd d td t|| dS |jrt|trt|d}nttjd d td t|| dS )zuuencode/uudecode main programr   Nz'usage: %prog [-d] [-t] [input [output]])usagez-dz--decoder   zDecode (instead of encode)?F
store_true)desthelpdefaultactionz-tz--texttextz2data is text, encoded format unix-compatible text?r/   zincorrect number of argumentsr1   r   z: cannot do -t to stdoutr   z: cannot do -t from stdin)optparseZOptionParserZ
add_option
parse_argsr$   errorr   exitr   r   r    r   rL   r   r   r   printargvr   )rM   parseroptionsargsinputoutputr   r   r	   test   s6   





rX   __main__)NN)NNF)__doc__r%   r   r   __all__	Exceptionr   r   r   rX   r   r   r   r   r	   <module>   s   
:C&
