ó DÑÕfc@s®dZddlZddlZddlZddlZdddgZdefd„ƒYZedƒ\Z Z Z dZ d Z ed ƒZy<dd lmZmZdd lmZd „Zd„ZWn@ek rdd$d„ƒYZd„Zdd%d„ƒYZnXdd&d„ƒYZdd'd„ƒYZdd(d„ƒYZd„Zdd)d„ƒYZdd*d„ƒYZdd+d „ƒYZd!„Zd"„Z e!d#krªe ƒndS(,s‰Macintosh binhex compression/decompression. easy interface: binhex(inputfilename, outputfilename) hexbin(inputfilename, outputfilename) iÿÿÿÿNtbinhexthexbintErrorcBseZRS((t__name__t __module__(((s/usr/lib64/python2.7/binhex.pyRsii€i@i(tFSSpectFInfo(topenrfcCst|ƒjƒ}tjj|ƒ\}}t|dƒ}|jddƒ|jƒ}t|dƒ}|jddƒ|jƒ}||||fS(Ntrbiis*rb( Rt FSpGetFInfotostpathtsplittopentseekttellR(tnametfinfotdirtfiletfptdlentrlen((s/usr/lib64/python2.7/binhex.pyt getfileinfo3s  cGs*|sd}nd|d}t||ƒS(Ns*rbt*i(R(Rtmode((s/usr/lib64/python2.7/binhex.pytopenrsrc?s RcBseZd„ZRS(cCsd|_d|_d|_dS(Ns????i(tTypetCreatortFlags(tself((s/usr/lib64/python2.7/binhex.pyt__init__Ls  (RRR(((s/usr/lib64/python2.7/binhex.pyRKscCsÖtƒ}t|ƒ}t|ƒjdƒ}xF|D]5}|jƒ r1|dksbt|ƒdkr1Pq1q1Wd|_|jddƒ|jƒ}|jƒt j j |ƒ\}}|j ddd ƒ}|||dfS( Nit itTEXTiit:t-i( RR treadtisspacetordRRRtcloseR R R treplace(RRRtdatatctdsizeRR((s/usr/lib64/python2.7/binhex.pyRQs   +   RcBs,eZd„Zd„Zd„Zd„ZRS(cGsdS(N((Rtargs((s/usr/lib64/python2.7/binhex.pyRcscGsdS(Nt((RR,((s/usr/lib64/python2.7/binhex.pyR$fscGsdS(N((RR,((s/usr/lib64/python2.7/binhex.pytwriteiscCsdS(N((R((s/usr/lib64/python2.7/binhex.pyR'ls(RRRR$R.R'(((s/usr/lib64/python2.7/binhex.pyRbs   t_HqxcoderenginecBs2eZdZd„Zd„Zd„Zd„ZRS(s(Write data to the coder in 3-byte chunkscCs,||_d|_d|_td|_dS(NR-i(tofpR)thqxdatatLINELENtlinelen(RR0((s/usr/lib64/python2.7/binhex.pyRrs   cCs~|j||_t|jƒ}|dd}|j| }|j||_|sTdS|jtj|ƒ|_|jdƒdS(Nii(R)tlenR1tbinasciitb2a_hqxt_flush(RR)tdatalenttodo((s/usr/lib64/python2.7/binhex.pyR.xs cCs—d}xZ|t|jƒ|jkrb||j}|jj|j||!dƒt|_|}q W|j||_|r“|jj|jdƒndS(Nis s: (R4R1R3R0R.R2(Rtforcetfirsttlast((s/usr/lib64/python2.7/binhex.pyR7ƒs   cCsL|jr(|jtj|jƒ|_n|jdƒ|jjƒ|`dS(Ni(R)R1R5R6R7R0R'(R((s/usr/lib64/python2.7/binhex.pyR'Žs    (RRt__doc__RR.R7R'(((s/usr/lib64/python2.7/binhex.pyR/os   t_RlecoderenginecBs)eZdZd„Zd„Zd„ZRS(s4Write data to the RLE-coder in suitably large chunkscCs||_d|_dS(NR-(R0R)(RR0((s/usr/lib64/python2.7/binhex.pyR™s cCsX|j||_t|jƒtkr)dStj|jƒ}|jj|ƒd|_dS(NR-(R)R4tREASONABLY_LARGER5t rlecode_hqxR0R.(RR)trledata((s/usr/lib64/python2.7/binhex.pyR.s cCsE|jr.tj|jƒ}|jj|ƒn|jjƒ|`dS(N(R)R5R@R0R.R'(RRA((s/usr/lib64/python2.7/binhex.pyR'¥s   (RRR=RR.R'(((s/usr/lib64/python2.7/binhex.pyR>–s  tBinHexcBsPeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(c Csº|\}}}}t|ƒtdƒkrB|}t|dƒ}n|jdƒt|ƒ}t|ƒ|_d|_|dkr‹tƒ}n||_ ||_ |j ||ƒt |_ dS(NR-tws0(This file must be converted with BinHex 4.0) :i(ttypeR R.R/R>R0tcrctNoneRRRt _writeinfot _DID_HEADERtstate( Rtname_finfo_dlen_rlenR0RRRRtofnamethqxer((s/usr/lib64/python2.7/binhex.pyR­s       c Cs¥t|ƒ}|dkr$td‚nt|ƒ|d}|j|j}tjd|jƒ}tjd|j|j ƒ}||||}|j |ƒ|j ƒdS(Ni?sFilename too longts>hs>ii( R4RtchrRRtstructtpackRRRt_writet _writecrc( RRRtnltdtd2td3td4tinfo((s/usr/lib64/python2.7/binhex.pyRG½s    cCs,tj||jƒ|_|jj|ƒdS(N(R5tcrc_hqxRER0R.(RR)((s/usr/lib64/python2.7/binhex.pyRQËscCsJ|jdkrd}nd}|jjtj||jƒƒd|_dS(Nis>hs>H(RER0R.RORP(Rtfmt((s/usr/lib64/python2.7/binhex.pyRRÏs  cCsB|jtkrtd‚n|jt|ƒ|_|j|ƒdS(NsWriting data at the wrong time(RIRHRRR4RQ(RR)((s/usr/lib64/python2.7/binhex.pyR.Ùs cCs<|jdkr%td|jf‚n|jƒt|_dS(NisIncorrect data size, diff=%r(RRRRRt _DID_DATARI(R((s/usr/lib64/python2.7/binhex.pyt close_dataßs cCs^|jtkr|jƒn|jtkr7td‚n|jt|ƒ|_|j|ƒdS(Ns'Writing resource data at the wrong time(RIR[R\RRR4RQ(RR)((s/usr/lib64/python2.7/binhex.pyt write_rsrcås   cCs†|jtkr|jƒn|jtkr7td‚n|jdkr\td|jf‚n|jƒ|jjƒd|_|`dS(NsClose at the wrong timeis$Incorrect resource-datasize, diff=%r( RIR[R\RRRRR0R'RF(R((s/usr/lib64/python2.7/binhex.pyR'ís     ( RRRRGRQRRR.R\R]R'(((s/usr/lib64/python2.7/binhex.pyRB¬s      cCs½t|ƒ}t||ƒ}t|dƒ}x)|jdƒ}|sFPn|j|ƒq-|jƒ|jƒt|dƒ}x)|jdƒ}|s•Pn|j|ƒq||jƒ|jƒdS(s@(infilename, outfilename) - Create binhex-encoded copy of a fileRiôN( RRBR R$R.R\R'RR](tinptoutRR0tifpRT((s/usr/lib64/python2.7/binhex.pyRús$    t_HqxdecoderenginecBs)eZdZd„Zd„Zd„ZRS(s*Read data via the decoder in 4-byte chunkscCs||_d|_dS(Ni(R`teof(RR`((s/usr/lib64/python2.7/binhex.pyRs cCsód}|}xà|dkrî|jr(|S|ddd}|jj|ƒ}xeytj|ƒ\}|_PWntjk r‚nX|jjdƒ}|s§td‚n||}qO||}|t|ƒ}| r|j rtd‚qqW|S(s&Read at least wtd bytes (or until EOF)R-iiiiisPremature EOF on binhex file(RbR`R$R5ta2b_hqxt IncompleteRR4(RttotalwtdtdecdatatwtdR)t decdatacurtnewdata((s/usr/lib64/python2.7/binhex.pyR$s.    cCs|jjƒdS(N(R`R'(R((s/usr/lib64/python2.7/binhex.pyR'9s(RRR=RR$R'(((s/usr/lib64/python2.7/binhex.pyRas  "t_RledecoderenginecBs2eZdZd„Zd„Zd„Zd„ZRS(sRead data via the RLE-codercCs(||_d|_d|_d|_dS(NR-i(R`t pre_buffert post_bufferRb(RR`((s/usr/lib64/python2.7/binhex.pyR?s   cCsS|t|jƒkr2|j|t|jƒƒn|j| }|j||_|S(N(R4Rlt_fill(RRgtrv((s/usr/lib64/python2.7/binhex.pyR$Es  cCs$|j|jj|dƒ|_|jjrU|jtj|jƒ|_d|_dSt|jƒ}|jdtdtkrŒ|d}nd|jdtkr¬|d}nD|jdtdkrÐ|d}n |jdtkræn |d }|jtj|j| ƒ|_|j||_dS( NiR-iýÿÿÿRMiiÿÿÿÿiiþÿÿÿi( RkR`R$RbRlR5t rledecode_hqxR4tRUNCHAR(RRgtmark((s/usr/lib64/python2.7/binhex.pyRmLs&        cCs|jjƒdS(N(R`R'(R((s/usr/lib64/python2.7/binhex.pyR'os(RRR=RR$RmR'(((s/usr/lib64/python2.7/binhex.pyRj<s    #tHexBincBsPeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(cCs½t|ƒtdƒkr't|ƒ}nxa|jdƒ}|sKtd‚n|dkr]q*n|dkrmPn|dkr*|jƒ}q*q*t|ƒ}t|ƒ|_d|_|j ƒdS(NR-isNo binhex data founds R"s i( RDR R$RtreadlineRaRjR`REt _readheader(RR`tchtdummythqxifp((s/usr/lib64/python2.7/binhex.pyRss       cCs.|jj|ƒ}tj||jƒ|_|S(N(R`R$R5RYRE(RR4R)((s/usr/lib64/python2.7/binhex.pyt_read‹scCsktjd|jjdƒƒdd@}|jd@|_||jkr^td|j|f‚nd|_dS(Ns>hiiiÿÿsCRC error, computed %x, read %x(ROtunpackR`R$RER(Rtfilecrc((s/usr/lib64/python2.7/binhex.pyt _checkcrcs &cCsú|jdƒ}|jt|ƒƒ}|jdƒ}|jƒ|dd!}|dd!}tjd|dd!ƒd}tjd |dd !ƒd|_tjd |d d !ƒd|_||_tƒ|_||j_ ||j_ ||j_ t |_ dS(Niiiii s>hi is>liiii i ii(RxR&R{RORyRRtFNameRRRRRHRI(RR4tfnametrestRDtcreatortflags((s/usr/lib64/python2.7/binhex.pyRtšs          cGs™|jtkrtd‚n|r@|d}t||jƒ}n |j}d}x3t|ƒ|kr„||j|t|ƒƒ}qRW|j||_|S(NsRead data at wrong timeiR-(RIRHRtminRR4Rx(RtnRn((s/usr/lib64/python2.7/binhex.pyR$®s   !cCsP|jtkrtd‚n|jr9|j|jƒ}n|jƒt|_dS(Nsclose_data at wrong time(RIRHRRRxR{R[(RRv((s/usr/lib64/python2.7/binhex.pyR\¼s    cGs‚|jtkr|jƒn|jtkr7td‚n|r\|d}t||jƒ}n |j}|j||_|j|ƒS(Ns Read resource data at wrong timei(RIRHR\R[RRRRx(RR‚((s/usr/lib64/python2.7/binhex.pyt read_rsrcÄs    cCsB|jr|j|jƒ}n|jƒt|_|jjƒdS(N(RRƒR{t _DID_RSRCRIR`R'(RRv((s/usr/lib64/python2.7/binhex.pyR'Ñs    ( RRRRxR{RtR$R\RƒR'(((s/usr/lib64/python2.7/binhex.pyRrrs      cCsît|ƒ}|j}|s'|j}nt|dƒ}x)|jdƒ}|sRPn|j|ƒq9|jƒ|jƒ|jdƒ}|ràt |dƒ}|j|ƒx)|jdƒ}|sÃPn|j|ƒqª|jƒn|jƒdS(s0(infilename, outfilename) - Decode binhexed filetwbiôN( RrRR|R R$R.R'R\RƒR(R^R_R`RR0RT((s/usr/lib64/python2.7/binhex.pyRØs.       cCsDtjd}t||dƒt|d|dƒtjdƒdS(Nis.hqxs.viahqx(tsystargvRRtexit(R}((s/usr/lib64/python2.7/binhex.pyt_testôs t__main__((((((((("R=R†R ROR5t__all__t ExceptionRtrangeRHR[R„R?R2RNRpt Carbon.FileRRtMacOSRRRt ImportErrorR/R>RBRRaRjRrRR‰R(((s/usr/lib64/python2.7/binhex.pyts<         'N ,6f