ó zfc@s¥dZddlZddlZddlZddlZdddgZdefd„ƒYZdZdZ d Z d Z e d ƒZ y<dd lmZmZdd lmZd„Zd„ZWn@ek rýdd%d„ƒYZd„Zdd&d„ƒYZnXdd'd„ƒYZdd(d„ƒYZdd)d„ƒYZd„Zdd*d„ƒYZdd+d„ƒYZd d,d!„ƒYZd"„Zd#„Zed$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.pyRsiii€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 getfileinfo4s  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__Ms  (RRR(((s/usr/lib64/python2.7/binhex.pyRLscCsÖ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.pyRRs   +   RcBs,eZd„Zd„Zd„Zd„ZRS(cGsdS(N((Rtargs((s/usr/lib64/python2.7/binhex.pyRdscGsdS(Nt((RR,((s/usr/lib64/python2.7/binhex.pyR$gscGsdS(N((RR,((s/usr/lib64/python2.7/binhex.pytwritejscCsdS(N((R((s/usr/lib64/python2.7/binhex.pyR'ms(RRRR$R.R'(((s/usr/lib64/python2.7/binhex.pyRcs   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.pyRss   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.ys 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/ps   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 longss>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.pyRPÌscCsJ|jdkrd}nd}|jjtj||jƒƒd|_dS(Nis>hs>H(RER0R.RNRO(Rtfmt((s/usr/lib64/python2.7/binhex.pyRQÐs  cCsB|jtkrtd‚n|jt|ƒ|_|j|ƒdS(NsWriting data at the wrong time(RIRHRRR4RP(RR)((s/usr/lib64/python2.7/binhex.pyR.Ús cCs<|jdkr%td|jf‚n|jƒt|_dS(NisIncorrect data size, diff=%r(RRRRQt _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(RIRZR[RRR4RP(RR)((s/usr/lib64/python2.7/binhex.pyt write_rsrcæs   cCs§|jdkrdSzj|jtkr2|jƒn|jtkrMtd‚n|jdkrrtd|jf‚n|jƒWdd|_|j}|`|jƒXdS(NsClose at the wrong timeis$Incorrect resource-datasize, diff=%r( RIRFRZR[RRRQR0R'(RR0((s/usr/lib64/python2.7/binhex.pyR'îs    ( RRRRGRPRQR.R[R\R'(((s/usr/lib64/python2.7/binhex.pyRB­s      cCs¿t|ƒ}t||ƒ}t|dƒ}x*|jdƒ}|sFPn|j|ƒq-W|jƒ|jƒt|dƒ}x*|jdƒ}|s–Pn|j|ƒq}W|jƒ|jƒdS(s@(infilename, outfilename) - Create binhex-encoded copy of a fileRiôN( RRBR R$R.R[R'RR\(tinptoutRR0tifpRS((s/usr/lib64/python2.7/binhex.pyRs$    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|ƒ}xfytj|ƒ\}|_PWntjk r‚nX|jjdƒ}|s§td‚n||}qOW||}|t|ƒ}| r|j rtd‚qqW|S(s&Read at least wtd bytes (or until EOF)R-iiiiisPremature EOF on binhex file(RaR_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'?s(RRR=RR$R'(((s/usr/lib64/python2.7/binhex.pyR`s  "t_RledecoderenginecBs2eZdZd„Zd„Zd„Zd„ZRS(sRead data via the RLE-codercCs(||_d|_d|_d|_dS(NR-i(R_t pre_buffert post_bufferRa(RR_((s/usr/lib64/python2.7/binhex.pyREs   cCsS|t|jƒkr2|j|t|jƒƒn|j| }|j||_|S(N(R4Rkt_fill(RRftrv((s/usr/lib64/python2.7/binhex.pyR$Ks  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ýÿÿÿsiiÿÿÿÿiiþÿÿÿi( RjR_R$RaRkR5t rledecode_hqxR4tRUNCHAR(RRftmark((s/usr/lib64/python2.7/binhex.pyRlRs&        cCs|jjƒdS(N(R_R'(R((s/usr/lib64/python2.7/binhex.pyR'us(RRR=RR$RlR'(((s/usr/lib64/python2.7/binhex.pyRiBs    #tHexBincBsPeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(cCs¾t|ƒtdƒkr't|ƒ}nxb|jdƒ}|sKtd‚n|dkr]q*n|dkrmPn|dkr*|jƒ}q*q*Wt|ƒ}t|ƒ|_d|_|j ƒdS(NR-isNo binhex data founds R"s i( RDR R$RtreadlineR`RiR_REt _readheader(RR_tchtdummythqxifp((s/usr/lib64/python2.7/binhex.pyRys       cCs.|jj|ƒ}tj||jƒ|_|S(N(R_R$R5RXRE(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(RNtunpackR_R$RER(Rtfilecrc((s/usr/lib64/python2.7/binhex.pyt _checkcrc–s &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(RwR&RzRNRxRRtFNameRRRRRHRI(RR4tfnametrestRDtcreatortflags((s/usr/lib64/python2.7/binhex.pyRs s          cGs™|jtkrtd‚n|r@|d}t||jƒ}n |j}d}x3t|ƒ|kr„||j|t|ƒƒ}qRW|j||_|S(NsRead data at wrong timeiR-(RIRHRtminRR4Rw(RtnRm((s/usr/lib64/python2.7/binhex.pyR$´s   !cCsP|jtkrtd‚n|jr9|j|jƒ}n|jƒt|_dS(Nsclose_data at wrong time(RIRHRRRwRzRZ(RRu((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[RZRR€RRw(RR((s/usr/lib64/python2.7/binhex.pyt read_rsrcÊs    cCs]|jdkrdSz,|jr4|j|jƒ}n|jƒWdd|_|jjƒXdS(N(RIRFRR‚RzR_R'(RRu((s/usr/lib64/python2.7/binhex.pyR'×s  ( RRRRwRzRsR$R[R‚R'(((s/usr/lib64/python2.7/binhex.pyRqxs      cCsðt|ƒ}|j}|s'|j}nt|dƒ}x*|jdƒ}|sRPn|j|ƒq9W|jƒ|jƒ|jdƒ}|rât |dƒ}|j|ƒx*|jdƒ}|sÄPn|j|ƒq«W|jƒn|jƒdS(s0(infilename, outfilename) - Decode binhexed filetwbiôN( RqRR{R R$R.R'R[R‚R(R]R^R_RR0RS((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 RNR5t__all__t ExceptionRRHRZR?R2RMRot Carbon.FileRRtMacOSRRRt ImportErrorR/R>RBRR`RiRqRR‡R(((s/usr/lib64/python2.7/binhex.pyts>         'S ,6j