U ÙAT^-c@sjdZddlZddlZddlZdddgZGdd„deƒZdddœd d„Zdd d„Zd d „Z e d krfe ƒdS)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 eZdZdS)rN)Ú__name__Z __module__Z __qualname__©rrú/usr/lib64/python3.8/uu.pyr'sF©Úbacktickc Csjg}zH|dkrtjj}n`t|tƒrz|dkr8tj |¡}|dkrfzt  |¡j }Wnt k rdYnXt |dƒ}|  |¡|dkrŒtjj}nt|tƒrªt |dƒ}|  |¡|dkr¶d}|dkrÂd}| dd¡}| dd ¡}| d |d @|f d ¡¡| d ¡}t|ƒdkr0| tj||d¡| d ¡}q|rB| d¡n | d¡W5|D]}| ¡qTXdS)z Uuencode fileú-NÚrbÚwbi¶Z z\nz z\rz begin %o %s iÿÚasciii-rrs` end s end )ÚcloseÚsysÚstdinÚbufferÚ isinstanceÚstrÚosÚpathZbasenameZstatZst_modeZAttributeErrorÚopenÚappendÚstdoutZreplaceÚwriterZreadÚlenÚbinasciiZb2a_uu)Úin_fileÚout_fileZnameÚmoderÚ opened_filesÚfÚdatarrrr*sF             c Csg}|dkrtjj}nt|tƒr4t|dƒ}| |¡zÀ| ¡}|sLt dƒ‚|  d¡sXq8|  dd¡}t |ƒdkr8|ddkr8zt |d d ƒWqªWq8tk r¦Yq8Xq8|d krÞ|d d ¡ d ¡}tj |¡rÞt d|ƒ‚|d krôt |d d ƒ}|dkrtjj}n0t|tƒr8t|dƒ}t ||¡|}| |¡| ¡} | ræ|  d ¡dkræzt | ¡} Wnjtj k rÎ} zH| ddd@ddd} t | d | …¡} |s¾tj d| ¡W5d } ~ XYnX| | ¡| ¡} q@| sôt dƒ‚W5|D]}| ¡qüXd S)zDecode uuencoded filer r z'No valid begin line found in input filesbegins éiréiNs r z"Cannot overwrite existing file: %sr sendi i?iiz Warning: %s zTruncated input file)rrrrrrrr ZreadlinerZ startswithZsplitrZintZ ValueErrorZrstriprrrZexistsrZchmodZstriprZa2b_uuZstderrr) rrrZquietrrZhdrZ hdrfieldsZfpZsr ZvZnbytesrrrrds^              "   cCs4ddl}|jdd}|jddddd d d |jd d ddd d 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)zuuencode/uudecode main programrNz'usage: %prog [-d] [-t] [input [output]])Zusagez-dz--decoderzDecode (instead of encode)?FZ store_true)ZdestZhelpZdefaultZactionz-tz--textÚtextz2data is text, encoded format unix-compatible text?r!zincorrect number of argumentsr"r z: cannot do -t to stdoutr z: cannot do -t from stdin)ÚoptparseZ OptionParserZ add_optionZ parse_argsrZerrorrZexitrrrrr#rrrZprintZargvr)r$ZparserZoptionsZargsZinputZoutputrrrÚtest§s6              r%Z__main__)NN)NNF) Z__doc__rrrZ__all__Z Exceptionrrrr%rrrrrZs : C&