B 2r2q@sddlZddlZddlZdddddddd d d d d ddddddgZeefZddZdBddZdCddZ ddZ ddZ e ddZ e ddZddZddZdZdadad dZdDd!d Zd"d ZdEd#d Zdadad$Zd%ZdFd&d'Zddddd(d)dZddd*d+d,dZd-Zda da!da"dGd.d Z#d/d Z$d0Z%e%d1d2Z&d3dZ'd4dZ(d5d6Z)d7dZ*d8d9Z+d:dZ,d;d<Z-d=d>Z.d?d@Z/e0dAkre.dS)HNencodedecode encodebytes decodebytes b64encode b64decode b32encode b32decode b16encode b16decode b85encode b85decode a85encode a85decodestandard_b64encodestandard_b64decodeurlsafe_b64encodeurlsafe_b64decodecCsxt|tr2y |dStk r0tdYnXt|tr@|Sy t|Stk rrtd|j j dYnXdS)Nasciiz4string argument should contain only ASCII charactersz>argument should be a bytes-like object or ASCII string, not %r) isinstancestrrUnicodeEncodeError ValueError bytes_types memoryviewtobytes TypeError __class____name__)sr )/opt/alt/python37/lib/python3.7/base64.py_bytes_from_decode_data"s    r"cCs,tj|dd}|dk r(|td|S|S)NF)newlines+/)binascii b2a_base64 translatebytes maketrans)raltcharsencodedr r r!r3sFcCsNt|}|dk r*t|}|t|d}|rDtd|sDtdt|S)Ns+/s[A-Za-z0-9+/]*={0,2}zNon-base64 digit found) r"r&r'r(re fullmatchr$Error a2b_base64)rr)Zvalidater r r!rAs cCst|S)N)r)rr r r!rZscCst|S)N)r)rr r r!rass+/s-_cCst|tS)N)rr&_urlsafe_encode_translation)rr r r!roscCst|}|t}t|S)N)r"r&_urlsafe_decode_translationr)rr r r!rxs  s ABCDEFGHIJKLMNOPQRSTUVWXYZ234567csBtdkr,ddtDfddDadt|tsBt|}t|d}|rb|dd|}t}tj }t}xjt dt|dD]V}||||dd}|||d?||d ?d @||d ?d @||d @7}qW|d krd |dd<nF|dkr d|dd<n.|dkr$d|dd<n|dkr:d|dd<t |S)NcSsg|]}t|fqSr )r').0ir r r! szb32encode..csg|]}D] }||q qSr r )r1ab)b32tabr r!r3srbigi s======is====s====) _b32tab2 _b32alphabetrrrrlen bytearrayint from_bytesranger')rleftoverr*rJZb32tab2r2cr )r6r!rs4   *    c CstdkrddttDat|}t|dr8td|dk r^t|}|t dd|}|rj| }t|}| d}|t|}t }t}xt dt|dD]l}|||d}d} y"x|D]} | d >|| } qWWn tk rtd dYnX|| d d 7}qW|ds(|d kr2td|rz|rz| d |K} | d d } d d |d} | d| |dd<t|S)NcSsi|]\}}||qSr r )r1kvr r r! szb32decode..zIncorrect paddings01OrCrr7zNon-base32 digit foundr9>rr=r@rB+)_b32rev enumeraterFr"rGr$r-r&r'r(upperrstriprHrKKeyErrorto_bytes) rcasefoldZmap01lZpadcharsdecodedZb32revr2ZquantaaccrMZlastrLr r r!r s@         cCst|S)N)r$ZhexlifyrX)rr r r!r scCs4t|}|r|}td|r*tdt|S)Ns [^0-9A-F]zNon-base16 digit found)r"rXr+searchr$r-Z unhexlify)rr\r r r!r s   s<~s~>c st|tst|}t| d}|r4|d|}tdt|d|}fdd|D}|r|s|ddkrdd |d<|dd| |d<d |S) NrBr8z!%dIcsPg|]H}r|sdn6r$|dkr$dn&|d|dd|dqS)zi yi^ Ui9r )r1Zword)charschars2foldnuls foldspacesr r!r3!sz_85encode..rDrarr7) rrrrrGstructStructunpackjoin) r5rdrepadrfrgpaddingZwordschunksr )rdrerfrgr! _85encodes    rp)rgwrapcolrmadobecstdkr*ddtddDaddtDat|tt|d||rHtrt|rVdndfd dtd tD}|rt|d dkr|d d ||rt 7S)NcSsg|]}t|fqSr )r')r1r2r r r!r3Dsza85encode..!vcSsg|]}tD] }||q qSr ) _a85chars)r1r4r5r r r!r3EsTr>r=csg|]}||qSr r )r1r2)resultrqr r!r3MsrrDrh ) rurK _a85chars2rp _A85STARTmaxrGappendrl_A85END)r5rgrqrmrrror )rvrqr!r/s"   s )rgrr ignorecharsc Cst|}|rH|ts$tdt|tr<|dd}n |dd}tdj }g}|j }g}|j }|j } x|dD]} d| krdkr nnt|| t |dkrpd } x|D]} d | | d} qWy||| Wn"tj k rtd dYnX| qz| d kr.|r$td |dqz|rV| dkrV|rLtd|dqz| |krdqzqztd| qzWd|} dt |} | r| d| } | S)Nz1Ascii85 encoded byte sequences must end with {!r}r>z!Isuuuursur7rrczAscii85 overflowzzz inside Ascii85 5-tuplesyzy inside Ascii85 5-tuples zNon-Ascii85 digit found: %crhrB)r"endswithr|rformat startswithryrirjpackr{clearrGerrorrl)r5rgrrr}packIr^Zdecoded_appendZcurrZ curr_appendZ curr_clearxr_rvrnr r r!rXsV           sU0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~cCs2tdkr$ddtDaddtDat|tt|S)NcSsg|]}t|fqSr )r')r1r2r r r!r3szb85encode..cSsg|]}tD] }||q qSr ) _b85chars)r1r4r5r r r!r3s)r _b85alphabet _b85chars2rp)r5rmr r r!r s c CsZtdkr0dgdaxttD]\}}|t|<qWt|}t| d}|d|}g}tdj}xtdt|dD]}|||d}d}y"x|D]}|dt|}qWWnJt k rx2t|D]&\}}t|dkrt d||dqWYnXy| ||Wqttj k r2t d|dYqtXqtWd |} |rV| d| } | S) Nr7~z!Irrcz#bad base85 character at position %dz+base85 overflow in hunk starting at byte %drh)_b85decrWrr"rGrirjrrKrrr{rrl) r5r2rMrnoutrchunkr_jrvr r r!r s<       LrBr@cCs`xZ|t}|sPx0t|tkrB|tt|}|s8P||7}qWt|}||qWdS)N)read MAXBINSIZErGr$r%write)inputoutputrnsliner r r!rs   cCs,x&|}|sPt|}||qWdS)N)readliner$r.r)rrrrr r r!rs  c Csy t|}Wn8tk rD}zd|jj}t||Wdd}~XYnX|jdkrjd|j|jjf}t||jdkrd|j|jjf}t|dS)Nz"expected bytes-like object, not %s)rMr5Bz-expected single byte elements, not %r from %sr=z(expected 1-D data, not %d-D data from %s)rrrrrndim)rmerrmsgr r r!_input_type_checks    rcCsPt|g}x8tdt|tD]$}|||t}|t|qWd|S)Nrrh)rrKrGrr{r$r%rl)rpiecesr2rr r r!r s cCsddl}|dtdt|S)NrzAencodestring() is a deprecated alias since 3.1, use encodebytes()r>)warningswarnDeprecationWarningr)rrr r r! encodestringsrcCst|t|S)N)rr$r.)rr r r!rscCsddl}|dtdt|S)NrzHdecodestring() is a deprecated alias since Python 3.1, use decodebytes()r>)rrrr)rrr r r! decodestring$src Cs ddl}ddl}y||jddd\}}WnP|jk r~}z0|j|_t|td|jd|dWdd}~XYnXt}xF|D]>\}}|dkrt}|dkrt }|dkrt }|d krt dSqW|r |dd kr t |dd }|||jj WdQRXn||j j |jj dS) Nrr=Zdeutzusage: %s [-d|-e|-u|-t] [file|-] -d, -u: decode -e: encode (default) -t: encode and decode string 'Aladdin:open sesame'r>z-ez-dz-uz-t-rb)sysgetoptargvrstderrstdoutprintexitrrtestopenbufferstdin) rrZoptsargsrfuncor4fr r r!main.s0rcCs<d}tt|t|}tt|t|}tt|dS)NsAladdin:open sesame)rreprrr)Zs0s1s2r r r!rHs   r__main__)N)NF)FN)F)FFF)F)1r+rir$__all__r'rHrr"rrrrr(r/r0rrrFrErVrr r r rurxryr|rprrrrrrr r Z MAXLINESIZErrrrrrrrrrrr r r r! sf     & C  )H -