B €/g^‚6ã@sÚddlZddlZddlZddlZdddgZGdd„deƒZdZdZdZ dZ d Z Gd d „d ƒZ d d „Z Gdd„dƒZGdd„dƒZGdd„dƒZGdd„dƒZdd„ZGdd„dƒZGdd„dƒZGdd„dƒZdd„ZdS)éNÚbinhexÚhexbinÚErrorc@s eZdZdS)rN)Ú__name__Ú __module__Ú __qualname__©rrú/usr/lib64/python3.7/binhex.pyrséi€é@óc@seZdZdd„ZdS)ÚFInfocCsd|_d|_d|_dS)Nz????r)ÚTypeÚCreatorÚFlags)Úselfrrr Ú__init__0szFInfo.__init__N)rrrrrrrr r /sr c Csttƒ}t |d¡2}| d¡}d|kr,d|_| dd¡| ¡}WdQRXtj  |¡\}}|  ddd¡}|||dfS) NÚrbirZTEXTéú:ú-r ) r ÚioÚopenÚreadrÚseekÚtellÚosÚpathÚsplitÚreplace)ÚnameÚfinfoÚfpÚdataZdsizeÚdirÚfilerrr Ú getfileinfo5s  r&c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) ÚopenrsrccGsdS)Nr)rÚargsrrr rCszopenrsrc.__init__cGsdS)Nór)rr(rrr rFsz openrsrc.readcGsdS)Nr)rr(rrr ÚwriteIszopenrsrc.writecCsdS)Nr)rrrr ÚcloseLszopenrsrc.closeN)rrrrrr*r+rrrr r'Bsr'c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú_HqxcoderenginecCs ||_d|_d|_td|_dS)Nr)r )Úofpr#ÚhqxdataÚLINELENÚlinelen)rr-rrr rRsz_Hqxcoderengine.__init__cCsh|j||_t|jƒ}|dd}|jd|…}|j|d…|_|sHdS|jt |¡|_| d¡dS)Nér)r#Úlenr.ÚbinasciiÚb2a_hqxÚ_flush)rr#ZdatalenZtodorrr r*Xs   z_Hqxcoderengine.writecCsvd}xF|t|jƒ|jkrJ||j}|j |j||…d¡t|_|}qW|j|d…|_|rr|j |jd¡dS)Nró s: )r2r.r0r-r*r/)rZforceÚfirstZlastrrr r5cs z_Hqxcoderengine._flushcCs6|jr|jt |j¡|_| d¡|j ¡|`dS)Nr )r#r.r3r4r5r-r+)rrrr r+ns   z_Hqxcoderengine.closeN)rrrrr*r5r+rrrr r,Os  r,c@s$eZdZdd„Zdd„Zdd„ZdS)Ú_RlecoderenginecCs||_d|_dS)Nr))r-r#)rr-rrr rxsz_Rlecoderengine.__init__cCs@|j||_t|jƒtkrdSt |j¡}|j |¡d|_dS)Nr))r#r2ÚREASONABLY_LARGEr3Ú rlecode_hqxr-r*)rr#Úrledatarrr r*|s    z_Rlecoderengine.writecCs0|jrt |j¡}|j |¡|j ¡|`dS)N)r#r3r:r-r*r+)rr;rrr r+„s    z_Rlecoderengine.closeN)rrrrr*r+rrrr r8usr8c@sLeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dS)ÚBinHexc Cs |\}}}}d}t|tƒr.|}t |d¡}d}yR| d¡t|ƒ} t| ƒ|_d|_|dkr`t ƒ}||_ ||_ |  ||¡t |_Wn|r”| ¡‚YnXdS)NFÚwbTs0(This file must be converted with BinHex 4.0) :r)Ú isinstanceÚstrrrr*r,r8r-Úcrcr ÚdlenÚrlenÚ _writeinfoÚ _DID_HEADERÚstater+) rZname_finfo_dlen_rlenr-r r!rArBZclose_on_errorZofnameZhqxerrrr rŒs*       zBinHex.__init__c Cs´t|ƒ}|dkrtdƒ‚t|gƒ| d¡d}|j|j}}t|tƒrR| d¡}t|tƒrf| d¡}||}t  d|j ¡}t  d|j |j ¡} |||| } |  | ¡| ¡dS)Né?zFilename too longzlatin-1óz>hz>ii)r2rÚbytesÚencoderrr>r?ÚstructÚpackrrArBÚ_writeÚ _writecrc) rr r!ÚnlÚdÚtpZcrZd2Zd3Zd4Úinforrr rC£s     zBinHex._writeinfocCs t ||j¡|_|j |¡dS)N)r3Úcrc_hqxr@r-r*)rr#rrr rL¶sz BinHex._writecCs4|jdkrd}nd}|j t ||j¡¡d|_dS)Nrz>hz>H)r@r-r*rJrK)rZfmtrrr rMºs  zBinHex._writecrccCs0|jtkrtdƒ‚|jt|ƒ|_| |¡dS)NzWriting data at the wrong time)rErDrrAr2rL)rr#rrr r*Äs z BinHex.writecCs,|jdkrtd|jfƒ‚| ¡t|_dS)NrzIncorrect data size, diff=%r)rArrBrMÚ _DID_DATArE)rrrr Ú close_dataÊs zBinHex.close_datacCsB|jtkr| ¡|jtkr$tdƒ‚|jt|ƒ|_| |¡dS)Nz'Writing resource data at the wrong time)rErSrTrrBr2rL)rr#rrr Ú write_rsrcÐs   zBinHex.write_rsrccCsx|jdkrdSzJ|jtkr"| ¡|jtkr4tdƒ‚|jdkrNtd|jfƒ‚| ¡Wdd|_|j}|`| ¡XdS)NzClose at the wrong timerz$Incorrect resource-datasize, diff=%r)rErSrTrrBrMr-r+)rr-rrr r+Øs     z BinHex.closeN) rrrrrCrLrMr*rTrUr+rrrr r<‹s r<c Cst|ƒ}t||ƒ}t |d¡.}x| d¡}|s2P| |¡q"W| ¡WdQRXt|dƒ}x| d¡}|snP| |¡q^W|  ¡|  ¡dS)Nriô) r&r<rrrr*rTr'rUr+)ÚinpÚoutr!r-ÚifprOrrr rés"    c@s$eZdZdd„Zdd„Zdd„ZdS)Ú_HqxdecoderenginecCs||_d|_dS)Nr)rXÚeof)rrXrrr rsz_Hqxdecoderengine.__init__cCsºd}|}x¬|dkr´|jr|S|ddd}|j |¡}xRyt |¡\}|_PWntjk rfYnX|j d¡}|s€tdƒ‚||}q:W||}|t|ƒ}|s |js tdƒ‚q W|S)Nr)rrr1ér zPremature EOF on binhex file)rZrXrr3Za2b_hqxZ Incompleterr2)rZtotalwtdZdecdataÚwtdr#Z decdatacurÚnewdatarrr rs,       z_Hqxdecoderengine.readcCs|j ¡dS)N)rXr+)rrrr r+%sz_Hqxdecoderengine.closeN)rrrrrr+rrrr rYþs rYc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú_RledecoderenginecCs||_d|_d|_d|_dS)Nr)r)rXÚ pre_bufferÚ post_bufferrZ)rrXrrr r+sz_Rledecoderengine.__init__cCsD|t|jƒkr"| |t|jƒ¡|jd|…}|j|d…|_|S)N)r2r`Ú_fill)rr\Úrvrrr r1s z_Rledecoderengine.readcCsô|j|j |d¡|_|jjr>|jt |j¡|_d|_dSt|jƒ}|jdd…tdtkrl|d}nX|jdd…tkrˆ|d}n<|jdd…tdkr¨|d}n|jdd…tkr¼n|d }|jt |jd|…¡|_|j|d…|_dS) Nr[r)éýÿÿÿrGr1éÿÿÿÿréþÿÿÿr ) r_rXrrZr`r3Z rledecode_hqxr2ÚRUNCHAR)rr\Zmarkrrr ra8s&    z_Rledecoderengine._fillcCs|j ¡dS)N)rXr+)rrrr r+[sz_Rledecoderengine.closeN)rrrrrrar+rrrr r^(s#r^c@sLeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dS)ÚHexBincCsjt|tƒrt |d¡}x.| d¡}|s.tdƒ‚|dkr8q|dkrPqWt|ƒ}t|ƒ|_d|_ |  ¡dS)Nrr zNo binhex data foundó ó:r) r>r?rrrrrYr^rXr@Ú _readheader)rrXZchZhqxifprrr r_s    zHexBin.__init__cCs |j |¡}t ||j¡|_|S)N)rXrr3rRr@)rr2r#rrr Ú_readus z HexBin._readcCsNt d|j d¡¡dd@}|jd@|_||jkrDtd|j|fƒ‚d|_dS)Nz>hrriÿÿzCRC error, computed %x, read %x)rJÚunpackrXrr@r)rZfilecrcrrr Ú _checkcrczs   zHexBin._checkcrccCs¾| d¡}| t|ƒ¡}| d¡}| ¡|dd…}|dd…}t d|dd…¡d}t d|dd …¡d|_t d|d d…¡d|_||_tƒ|_||j_ ||j_ ||j_ t |_ dS) Nr ééé z>hé rz>lé)rkÚordrmrJrlrArBÚFNamer rrrrDrE)rr2ZfnameÚrestÚtypeZcreatorÚflagsrrr rj„s    zHexBin._readheadercGsn|jtkrtdƒ‚|r,|d}t||jƒ}n|j}d}x&t|ƒ|kr\|| |t|ƒ¡}q8W|j||_|S)NzRead data at wrong timerr))rErDrÚminrAr2rk)rÚnrbrrr r˜s  z HexBin.readcCs6|jtkrtdƒ‚|jr$| |j¡}| ¡t|_dS)Nzclose_data at wrong time)rErDrrArkrmrS)rÚdummyrrr rT¦s   zHexBin.close_datacGsZ|jtkr| ¡|jtkr$tdƒ‚|r>|d}t||jƒ}n|j}|j||_| |¡S)Nz Read resource data at wrong timer)rErDrTrSrrxrBrk)rryrrr Ú read_rsrc®s   zHexBin.read_rsrccCsD|jdkrdSz|jr"| |j¡}| ¡Wdd|_|j ¡XdS)N)rErBr{rmrXr+)rrzrrr r+»s   z HexBin.closeN) rrrrrkrmrjrrTr{r+rrrr rg^s  rgc Cs®t|ƒ}|j}|s|j}t |d¡&}x| d¡}|s8P| |¡q(WWdQRX| ¡| d¡}|r¢t |dƒ}| |¡x| d¡}|sŒP| |¡q|W|  ¡|  ¡dS)Nr=iô) rgr rtrrrr*rTr{r'r+)rVrWrXr!r-rOrrr rÆs,     )rrrJr3Ú__all__Ú ExceptionrrDrSr9r/rfr r&r'r,r8r<rrYr^rgrrrrr Ús*   &^*6h