�`^c@s�dZddlZddlZddlZddlZdddgZdefd��YZed�\Z Z
ZdZd Z
ed
�Zy<ddlmZmZddlmZd
�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/sys/lib/python2.7/binhex.pyRsii�i@i�(tFSSpectFInfo(topenrfcCs�t|�j�}tjj|�\}}t|d�}|jdd�|j�}t|d�}|jdd�|j�}||||fS(Ntrbiis*rb( RtFSpGetFInfotostpathtsplittopentseekttellR(tnametfinfotdirtfiletfptdlentrlen((s/sys/lib/python2.7/binhex.pytgetfileinfo3scGs*|sd}nd|d}t||�S(Ns*rbt*i(R(Rtmode((s/sys/lib/python2.7/binhex.pytopenrsrc?s RcBseZd�ZRS(cCsd|_d|_d|_dS(Ns????i(tTypetCreatortFlags(tself((s/sys/lib/python2.7/binhex.pyt__init__Ls (RRR(((s/sys/lib/python2.7/binhex.pyRKscCs�t�}t|�}t|�jd�}xF|D]5}|j�r1|dksbt|�dkr1Pq1q1Wd|_|jdd�|j�}|j�t j
j|�\}}|jddd �}|||dfS(
Nit itTEXTiit:t-i(
RR
treadtisspacetordRRRtcloseR
RRtreplace(RRRtdatatctdsizeRR((s/sys/lib/python2.7/binhex.pyRQs
+
RcBs,eZd�Zd�Zd�Zd�ZRS(cGsdS(N((Rtargs((s/sys/lib/python2.7/binhex.pyRcscGsdS(Nt((RR,((s/sys/lib/python2.7/binhex.pyR$fscGsdS(N((RR,((s/sys/lib/python2.7/binhex.pytwriteiscCsdS(N((R((s/sys/lib/python2.7/binhex.pyR'ls(RRRR$R.R'(((s/sys/lib/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/sys/lib/python2.7/binhex.pyRrs cCs~|j||_t|j�}|dd}|j| }|j||_|sTdS|jtj|�|_|jd�dS(Nii(R)tlenR1tbinasciitb2a_hqxt_flush(RR)tdatalenttodo((s/sys/lib/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/sys/lib/python2.7/binhex.pyR7�s
cCsL|jr(|jtj|j�|_n|jd�|jj�|`dS(Ni(R)R1R5R6R7R0R'(R((s/sys/lib/python2.7/binhex.pyR'�s
(RRt__doc__RR.R7R'(((s/sys/lib/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/sys/lib/python2.7/binhex.pyR�s cCsX|j||_t|j�tkr)dStj|j�}|jj|�d|_dS(NR-(R)R4tREASONABLY_LARGER5trlecode_hqxR0R.(RR)trledata((s/sys/lib/python2.7/binhex.pyR.�scCsE|jr.tj|j�}|jj|�n|jj�|`dS(N(R)[email protected]'(RRA((s/sys/lib/python2.7/binhex.pyR'�s
(RRR=RR.R'(((s/sys/lib/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/sys/lib/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/sys/lib/python2.7/binhex.pyRG�s
cCs,tj||j�|_|jj|�dS(N(R5tcrc_hqxRER0R.(RR)((s/sys/lib/python2.7/binhex.pyRQ�scCsJ|jdkrd}nd}|jjtj||j��d|_dS(Nis>hs>H(RER0R.RORP(Rtfmt((s/sys/lib/python2.7/binhex.pyRR�s
cCsB|jtkrtd�n|jt|�|_|j|�dS(NsWriting data at the wrong time(RIRHRRR4RQ(RR)((s/sys/lib/python2.7/binhex.pyR.�scCs<|jdkr%td|jf�n|j�t|_dS(NisIncorrect data size, diff=%r(RRRRRt _DID_DATARI(R((s/sys/lib/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/sys/lib/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/sys/lib/python2.7/binhex.pyR'�s
(
RRRRGRQRRR.R\R]R'(((s/sys/lib/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�( RRBR
R$R.R\R'RR](tinptoutRR0tifpRT((s/sys/lib/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/sys/lib/python2.7/binhex.pyRs cCs�d}|}x�dkr�jr(|S|ddd}|jj|�}xeytj|�\}|_PWntjk
r�nX|jjd�}|s�td�n||}qO||}|t|�}|r|jrtd�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/sys/lib/python2.7/binhex.pyR$s.
cCs|jj�dS(N(R`R'(R((s/sys/lib/python2.7/binhex.pyR'9s(RRR=RR$R'(((s/sys/lib/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_buffertpost_bufferRb(RR`((s/sys/lib/python2.7/binhex.pyR?s cCsS|t|j�kr2|j|t|j��n|j| }|j||_|S(N(R4Rlt_fill(RRgtrv((s/sys/lib/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�
|d }|jtj|j| �|_|j||_dS(
NiR-i�RMii�ii�i( RkR`R$RbRlR5t
rledecode_hqxR4tRUNCHAR(RRgtmark((s/sys/lib/python2.7/binhex.pyRmLs&
cCs|jj�dS(N(R`R'(R((s/sys/lib/python2.7/binhex.pyR'os(RRR=RR$RmR'(((s/sys/lib/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/sys/lib/python2.7/binhex.pyRss cCs.|jj|�}tj||j�|_|S(N(R`R$R5RYRE(RR4R)((s/sys/lib/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/sys/lib/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>hiis>liiii iii(RxR&R{RORyRRtFNameRRRRRHRI(RR4tfnametrestRDtcreatortflags((s/sys/lib/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/sys/lib/python2.7/binhex.pyR$�s
!cCsP|jtkrtd�n|jr9|j|j�}n|j�t|_dS(Nsclose_data at wrong time(RIRHRRRxR{R[(RRv((s/sys/lib/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[RR�RRx(RR�((s/sys/lib/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/sys/lib/python2.7/binhex.pyR'�s
(
RRRRxR{RtR$R\R�R'(((s/sys/lib/python2.7/binhex.pyRrrs
cCs�t|�}|j}|s'|j}nt|d�}x)|jd�}|sRPn|j|�q9|j�|j�|jd�}|r� |d�}|j|�x)|jd�}|s�Pn|j|�q�|j�n|j�dS(s0(infilename, outfilename) - Decode binhexed filetwbi�(
RrRR|R
R$R.R'R\R�R(R^R_R`RR0RT((s/sys/lib/python2.7/binhex.pyR�s.
cCsDtjd}t||d�t|d|d�tjd�dS(Nis.hqxs.viahqx(tsystargvRRtexit(R}((s/sys/lib/python2.7/binhex.pyt_test�s
t__main__((((((((("R=R�R
ROR5t__all__t ExceptionRtrangeRHR[R�R?R2RNRptCarbon.FileRRtMacOSRRRtImportErrorR/R>RBRRaRjRrRR�R(((s/sys/lib/python2.7/binhex.pyt<module>s<
'N ,6f
|