B €/g^‚6c@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.pyróéi€i@sc@seZdZdd„ZdS)ÚFInfocCsd|_d|_d|_dS)Nz????r)ÚTypeÚCreatorÚFlags©ÚselfrrrÚ__init__0szFInfo.__init__N)rrrrrrrrr /r r c Csttƒ}t |d¡2}| d¡}d|kr,d|_| dd¡| ¡}WdQRXtj  |¡\}}|  ddd¡}|||dfS) NÚrbirZTEXTéz:z-r ) r ÚioÚopenÚreadr ZseekZtellÚosZpathZsplitZreplace)ÚnameÚfinfoZfpÚdataZdsizeZdirZfilerrrÚ getfileinfo5s  rc@ó,eZdZdd„Zdd„Zdd„Zdd„Zd S) ÚopenrsrccGódS©Nr©rZargsrrrrCózopenrsrc.__init__cGsdS©Nórr rrrrFr!z openrsrc.readcGrrrr rrrÚwriteIr!zopenrsrc.writecCrrrrrrrÚcloseLr!zopenrsrc.closeN)rrrrrr$r%rrrrrBsrc@r) Ú_HqxcoderenginecCs ||_d|_d|_td|_dS)Nr#r )ÚofprÚhqxdataÚLINELENÚlinelen©rr'rrrrRóz_Hqxcoderengine.__init__cCsh|j||_t|jƒ}|dd}|jd|…}|j|d…|_|sHdS|jt |¡|_| d¡dS)Nér)rÚlenr(ÚbinasciiÚb2a_hqxÚ_flush)rrZdatalenZtodorrrr$Xs   z_Hqxcoderengine.writecCsvd}xF|t|jƒ|jkrJ||j}|j |j||…d¡t|_|}qW|j|d…|_|rr|j |jd¡dS)Nrs s: )r.r(r*r'r$r))rZforceZfirstZlastrrrr1cs z_Hqxcoderengine._flushcCs6|jr|jt |j¡|_| d¡|j ¡|`dS)Nr )rr(r/r0r1r'r%rrrrr%ns   z_Hqxcoderengine.closeN)rrrrr$r1r%rrrrr&Os  r&c@ó$eZdZdd„Zdd„Zdd„ZdS)Ú_RlecoderenginecCó||_d|_dSr")r'rr+rrrrxóz_Rlecoderengine.__init__cCs@|j||_t|jƒtkrdSt |j¡}|j |¡d|_dSr")rr.ÚREASONABLY_LARGEr/Ú rlecode_hqxr'r$)rrÚrledatarrrr$|s    z_Rlecoderengine.writecCs0|jrt |j¡}|j |¡|j ¡|`dSr)rr/r7r'r$r%)rr8rrrr%„s    z_Rlecoderengine.closeN)rrrrr$r%rrrrr3usr3c@óLeZdZdd„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&r3r'Úcrcr ÚdlenÚrlenÚ _writeinfoÚ _DID_HEADERÚstater%) rZname_finfo_dlen_rlenr'rrr?r@Zclose_on_errorZofnameZhqxerrrrrŒ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)Ni?zFilename too longzlatin-1óú>hz>ii)r.rZbytesZencoder r r<r=ÚstructÚpackrr?r@Ú_writeÚ _writecrc) rrrZnlÚdZtpZcrZd2Zd3Zd4ZinforrrrA£s     zBinHex._writeinfocCs t ||j¡|_|j |¡dSr)r/Úcrc_hqxr>r'r$©rrrrrrH¶sz BinHex._writecCs4|jdkrd}nd}|j t ||j¡¡d|_dS)NrrEz>H)r>r'r$rFrG)rZfmtrrrrIºs  zBinHex._writecrccCs0|jtkrtdƒ‚|jt|ƒ|_| |¡dS)NzWriting data at the wrong time)rCrBrr?r.rHrLrrrr$Äs z BinHex.writecCs,|jdkrtd|jfƒ‚| ¡t|_dS)NrzIncorrect data size, diff=%r)r?rr@rIÚ _DID_DATArCrrrrÚ close_dataÊs zBinHex.close_datacCsB|jtkr| ¡|jtkr$tdƒ‚|jt|ƒ|_| |¡dS)Nz'Writing resource data at the wrong time)rCrMrNrr@r.rHrLrrrÚ write_rsrcÐs   zBinHex.write_rsrccCsx|jdkrdSzJ|jtkr"| ¡|jtkr4tdƒ‚|jdkrNtd|jfƒ‚| ¡Wdd|_|j}|`| ¡XdS)NzClose at the wrong timerz$Incorrect resource-datasize, diff=%r)rCrMrNrr@rIr'r%r+rrrr%Øs     z BinHex.closeN) rrrrrArHrIr$rNrOr%rrrrr:‹s r:c Cst|ƒ}t||ƒ}t |d¡.}x| d¡}|s2P| |¡q"W| ¡WdQRXt|dƒ}x| d¡}|snP| |¡q^W|  ¡|  ¡dS)Nréô) rr:rrrr$rNrrOr%)ÚinpÚoutrr'ÚifprJrrrrés"    c@r2)Ú_HqxdecoderenginecCr4)Nr)rSÚeof©rrSrrrrr5z_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#rrr-ér zPremature EOF on binhex file)rUrSrr/Za2b_hqxZ Incompleterr.)rZtotalwtdZdecdataÚwtdrZ decdatacurZnewdatarrrrs,       z_Hqxdecoderengine.readcCó|j ¡dSr©rSr%rrrrr%%r!z_Hqxdecoderengine.closeN)rrrrrr%rrrrrTþs rTc@r) Ú_RledecoderenginecCs||_d|_d|_d|_dS)Nr#r)rSÚ pre_bufferÚ post_bufferrUrVrrrr+r,z_Rledecoderengine.__init__cCsD|t|jƒkr"| |t|jƒ¡|jd|…}|j|d…|_|Sr)r.r]Ú_fill)rrXÚrvrrrr1s 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) NrWr#iýÿÿÿrDr-iÿÿÿÿriþÿÿÿr ) r\rSrrUr]r/Z rledecode_hqxr.ÚRUNCHAR)rrXZmarkrrrr^8s&    z_Rledecoderengine._fillcCrYrrZrrrrr%[r!z_Rledecoderengine.closeN)rrrrrr^r%rrrrr[(s#r[c@r9)ÚHexBincCsjt|tƒrt |d¡}x.| d¡}|s.tdƒ‚|dkr8q|dkrPqWt|ƒ}t|ƒ|_d|_ |  ¡dS)Nrr zNo binhex data founds s:r) r<r=rrrrrTr[rSr>Ú _readheader)rrSZchZhqxifprrrr_s    zHexBin.__init__cCs |j |¡}t ||j¡|_|Sr)rSrr/rKr>)rr.rrrrÚ_readus z HexBin._readcCsNt d|j d¡¡dd@}|jd@|_||jkrDtd|j|fƒ‚d|_dS)NrErriÿÿzCRC error, computed %x, read %x)rFÚunpackrSrr>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 iii rEi rz>li)rcZordrerFrdr?r@ÚFNamer r r rrBrC)rr.ZfnameZrestZtypeZcreatorZflagsrrrrb„s    zHexBin._readheadercGsn|jtkrtdƒ‚|r,|d}t||jƒ}n|j}d}x&t|ƒ|kr\|| |t|ƒ¡}q8W|j||_|S)NzRead data at wrong timerr#)rCrBrÚminr?r.rc)rÚnr_rrrr˜s  z HexBin.readcCs6|jtkrtdƒ‚|jr$| |j¡}| ¡t|_dS)Nzclose_data at wrong time)rCrBrr?rcrerM©rZdummyrrrrN¦s   zHexBin.close_datacGsZ|jtkr| ¡|jtkr$tdƒ‚|r>|d}t||jƒ}n|j}|j||_| |¡S)Nz Read resource data at wrong timer)rCrBrNrMrrgr@rc)rrhrrrÚ read_rsrc®s   zHexBin.read_rsrccCsD|jdkrdSz|jr"| |j¡}| ¡Wdd|_|j ¡XdSr)rCr@rjrerSr%rirrrr%»s   z HexBin.closeN) rrrrrcrerbrrNrjr%rrrrra^s  rac Cs®t|ƒ}|j}|s|j}t |d¡&}x| d¡}|s8P| |¡q(WWdQRX| ¡| d¡}|r¢t |dƒ}| |¡x| d¡}|sŒP| |¡q|W|  ¡|  ¡dS)Nr;rP) rar rfrrrr$rNrjrr%)rQrRrSrr'rJrrrrÆs,     )rrrFr/Z__all__Z ExceptionrrBrMr6r)r`r rrr&r3r:rrTr[rarrrrrZs*   &^*6h