a ٶZgm�@sdddlZddlZddlZgd�ZGdd�de�Zddd�dd�Zdd d �Zd d �Ze d kr`e�dS)�N)�Error�encode�decodec@s eZdZdS)rN)�__name__� __module__� __qualname__�rr�/usr/lib64/python3.9/uu.pyr&srF��backtickc Cszg}�zX|dkrtjj}n^t|t�rx|dur8tj�|�}|durdzt�|�j }Wnt ybYn0t |d�}|� |�|dkr�tj j}nt|t�r�t |d�}|� |�|dur�d}|dur�d}|�dd�}|�dd�}|�d |d @|f�d ��|�d �}t|�d k�r,|�tj||d��|�d �}q�|�r>|�d�n |�d�W|D]}|���qNn|D]}|���qd0dS)N�-�rb�wbi�� z\n� z\rz begin %o %s i��ascii�-rr s` end s end )�sys�stdin�buffer� isinstance�str�os�path�basename�stat�st_mode�AttributeError�open�append�stdout�replace�writer�read�len�binasciiZb2a_uu�close)�in_file�out_file�name�moder � opened_files�data�frrr r)sJ                �rc Cs�g}|dkrtjj}nt|t�r4t|d�}|�|��z2|��}|sLtd��|� d�sXq8|� dd�}t |�dkr8|ddkr8zt |d d �Wq�Wq8t y�Yq80q8|du�r8|d�d ��d �}tj�|�r�td |����|� tj��s(dtj��|v�s(tj�r8|� tj��s(dtj��|v�r8td|�d���|du�rPt |d d �}|dk�rdtjj}n0t|t��r�t|d�}t�||�|}|�|�|��}|�rD|�d �dk�rDzt�|�} Wnltj�y,} zP|ddd@ddd} t�|d| ��} |�stj�d| �WYd} ~ n d} ~ 00|�| �|��}�q�|�sRtd��W|D]} | ���qXn|D]} | ���qn0dS)Nr r z'No valid begin line found in input filesbegin� ��r��s rz Cannot overwrite existing file: z..zRefusing to write to z due to directory traversalrsend� �?��z Warning: %s zTruncated input file)rrrrrrr�readliner� startswith�splitr$�int� ValueError�rstriprrr�exists�sep�altsepr �chmod�stripr%Za2b_uu�stderrr"r&) r'r(r*�quietr+ZhdrZ hdrfields�fp�sr,�v�nbytesr-rrr rcsv         �� ��       &   �rcCs4ddl}|jdd�}|jdddddd d �|jd d d ddd d �|��\}}t|�dkrl|�d�t�d�tjj }tj j }t|�dkr�|d}t|�dkr�|d}|j r�|j r�t |t�r�t|d�}nttjdd�t�d�t ||�nD|j �r&t |t��r t|d�}nttjdd�t�d�t||�dS)Nrz'usage: %prog [-d] [-t] [input [output]])�usagez-dz--decoderzDecode (instead of encode)?F� store_true)�dest�help�default�actionz-tz--text�textz2data is text, encoded format unix-compatible text?r/zincorrect number of argumentsr1rz: cannot do -t to stdoutr z: cannot do -t from stdin)�optparseZ OptionParserZ add_option� parse_argsr$�errorr�exitrrr rrNrrr�print�argvr)rO�parser�options�args�input�outputrrr �test�s6              rZ�__main__)NN)NNF) r%rr�__all__� ExceptionrrrrZrrrrr � s: J&