o ?Ogq@sdZgdZdZdZdZdZz ddlmZmZWn e y%dZdZYnwd d Z d d Z dddZ dddZ dddZdddZddZddZddZedkrWedSdS)zHConversions to/from quoted-printable transport encoding as per RFC 1521.)encodedecode encodestring decodestring=Ls0123456789ABCDEF)a2b_qpb2a_qpNcCsHt|tsJ|dvr |S|dkr|S|tkp#d|ko dkn S)zDecide whether a particular byte ordinal needs to be quoted. The 'quotetabs' flag indicates whether embedded tabs and spaces should be quoted. Note that line-ending tabs and spaces are always encoded, as per RFC 1521.  _ ~) isinstancebytesESCAPE)c quotetabsheaderr-/opt/alt/python310/lib64/python3.10/quopri.py needsquotings "rcCsBt|tr t|dks Jt|}ttt|dt|dfS)zQuote a single character.)rrlenordrHEXrrrrquote$s rFc Cs<tdur|}t|||d}||dS|dfdd}d} |}|s'nig} d} |dddkr;|dd}d} |D]"} t| f} t| ||rNt| } |rZ| d krZ| d q=| | q=|durh||t | } t | t kr|| dt dd d | t dd} t | t kss| }q |dur||| d dSdS) avRead 'input', apply quoted-printable encoding, and write to 'output'. 'input' and 'output' are binary file objects. The 'quotetabs' flag indicates whether embedded tabs and spaces should be quoted. Note that line-ending tabs and spaces are always encoded, as per RFC 1521. The 'header' flag indicates whether we are encoding spaces as _ as per RFC 1522.Nrr cSsn|r|dddvr||ddt|dd|dS|dkr.|t||dS|||dS)Nr .)writer)soutputlineEndrrrr#;s *zencode..writerrr!r r s= )r&) r readr#readlinerrrappend EMPTYSTRINGjoinr MAXLINESIZE) inputr%rrdataodatar#ZprevlinelineZoutlinestrippedrZthislinerrrr,sF            !rcCsFtdur t|||dSddlm}||}|}t|||||S)NrrBytesIO)r ior3rgetvalue)r$rrr3infpoutfprrrrjs rc Cstdur|}t||d}||dSd} |}|sndt|}}|dkr[||d|dkr[d} |d}|dkrZ||d|dvrZ|d}|dkrZ||d|dvsHnd} ||kr|||d} | dkrx|rx|d }|d}no| tkr|| }|d}nb|d|kr| sd} n[|d|kr||d|d tkr|t}|d }n<|d |krt||d|d rt||d |d r|tt||d|d f}|d }n|| }|d}||ksa| s||dd}q|r||dSdS) zRead 'input', apply quoted-printable decoding, and write to 'output'. 'input' and 'output' are binary file objects. If 'header' is true, decode underscore as space (per RFC 1522).Nrrrrr s r r ) r r'r#r(rrishexrunhex) r-r%rr.r/newr0inpartialrrrrrusL    $<,rcCsDtdur t||dSddlm}||}|}t|||d|S)Nr8rr2)r r4r3rr5)r$rr3r6r7rrrrs  rcCsVt|tsJd|kodknp*d|kodknp*d|ko(dkSS)zDReturn true if the byte ordinal 'c' is a hexadecimal digit in ASCII.09afAF)rrrrrrr;sHr;cCsd}|D]P}t|f}d|krdkrnntd}n.d|kr&dkr/nntdd}nd |kr9d krBnntd d}nJd t||d t||}q|S)z.Get the integer value of a hexadecimal number.rrArB0rCrDa rErFFznon-hex digit r)rrrepr)r$bitsrr>rrrr<s  r<c Csddl}ddl}z||jddd\}}Wn,|jyC}z|j|_t|tdtdtd|dWYd}~nd}~wwd}d}|D]\}}|d krTd }|d krZd }qJ|rl|rl|j|_td |d|sqd g}d} |D]W} | d kr|jj } n&zt | d} Wnt y}z|j d| |fd} WYd}~qud}~wwz|rt | |jj nt| |jj |W| d kr| qu| d kr| ww| r|| dSdS)NrrZtdz"usage: quopri [-t | -d] [file] ...z-t: quote tabsz-d: decode; default encoder9Fz-tTz-dz -t and -d are mutually exclusive-rbz%s: can't open (%s) )sysgetoptargverrorstderrstdoutprintexitstdinbufferopenOSErrorr#rrclose) rNrOZoptsargsmsgZdecoZtabsorHstsfilefprrrmainsd        ra__main__)F)FF)__doc____all__rr,rr*Zbinasciir r ImportErrorrrrrrrr;r<ra__name__rrrrs0   > + .