AlkantarClanX12

Your IP : 18.224.70.11


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/binhex.cpython-34.pyc

�
e fh6�@s9dZddlZddlZddlZddlZdddgZGdd�de�ZdZdZ	dZ
d	Zd
ZGdd�d�Z
d
d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�Zdd�ZGdd�d�ZGdd�d�ZGdd�d�Zdd�ZdS)z�Macintosh binhex compression/decompression.

easy interface:
binhex(inputfilename, outputfilename)
hexbin(inputfilename, outputfilename)
�N�binhex�hexbin�Errorc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�+/opt/alt/python34/lib64/python3.4/binhex.pyrs�i��@s�c@seZdZdd�ZdS)�FInfocCsd|_d|_d|_dS)Nz????r)�Type�Creator�Flags)�selfrrr	�__init__0s		zFInfo.__init__N)rrrrrrrr	r/src
Cs�t�}tj|d��J}|jd�}d|krEd|_n|jdd�|j�}WdQXtjj	|�\}}|j
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&Bsr&c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_Hqxcoderenginez(Write data to the coder in 3-byte chunkscCs,||_d|_d|_td|_dS)Nr(r
)�ofpr"�hqxdata�LINELEN�linelen)rr,rrr	rRs			z_Hqxcoderengine.__init__cCs�|j||_t|j�}|dd}|jd|�}|j|d�|_|s`dS|jtj|�|_|jd�dS)N�r)r"�lenr-�binascii�b2a_hqx�_flush)rr"ZdatalenZtodorrr	r)Xsz_Hqxcoderengine.writecCs�d}x]|t|j�|jkre||j}|jj|j||�d�t|_|}q	W|j|d�|_|r�|jj|jd�ndS)Nrs
s:
)r1r-r/r,r)r.)rZforce�first�lastrrr	r4cs
!	
z_Hqxcoderengine._flushcCsL|jr(|jtj|j�|_n|jd�|jj�|`dS)Nr
)r"r-r2r3r4r,r*)rrrr	r*ns
	

z_Hqxcoderengine.closeN)rrr�__doc__rr)r4r*rrrr	r+Os
r+c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�_Rlecoderenginez4Write data to the RLE-coder in suitably large chunkscCs||_d|_dS)Nr()r,r")rr,rrr	rxs	z_Rlecoderengine.__init__cCsX|j||_t|j�tkr)dStj|j�}|jj|�d|_dS)Nr()r"r1�REASONABLY_LARGEr2�rlecode_hqxr,r))rr"�rledatarrr	r)|sz_Rlecoderengine.writecCsE|jr.tj|j�}|jj|�n|jj�|`dS)N)r"r2r:r,r)r*)rr;rrr	r*�s
	
z_Rlecoderengine.closeN)rrrr7rr)r*rrrr	r8usr8c@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�BinHexc
	Cs�|\}}}}d}t|t�rH|}tj|d�}d}nyx|jd�t|�}	t|	�|_d|_|dkr�t	�}n||_
||_|j||�t
|_Wn|r�|j�n�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,rr rArBZclose_on_errorZofnameZhqxerrrr	r�s*	
			

zBinHex.__init__cCst|�}|dkr'td��nt|g�|jd�d}|j|j}}t|t�r{|jd�}nt|t�r�|jd�}n||}tj	d|j
�}tj	d|j|j�}	||||	}
|j
|
�|j�dS)N�?zFilename too longzlatin-1sz>hz>ii)r1r�bytes�encoder
rr>r?�struct�packrrArB�_write�	_writecrc)rrr �nl�dZtpZcrZd2Zd3Zd4�inforrr	rC�s 

zBinHex._writeinfocCs,tj||j�|_|jj|�dS)N)r2�crc_hqxr@r,r))rr"rrr	rK�sz
BinHex._writecCsJ|jdkrd}nd}|jjtj||j��d|_dS)Nrz>hz>H)r@r,r)rIrJ)rZfmtrrr	rL�s
	zBinHex._writecrccCsE|jtkrtd��n|jt|�|_|j|�dS)NzWriting data at the wrong time)rErDrrAr1rK)rr"rrr	r)�szBinHex.writecCs?|jdkr(td|jf��n|j�t|_dS)NrzIncorrect data size, diff=%r)rArrBrL�	_DID_DATArE)rrrr	�
close_data�s
zBinHex.close_datacCsa|jtkr|j�n|jtkr:td��n|jt|�|_|j|�dS)Nz'Writing resource data at the wrong time)rErQrRrrBr1rK)rr"rrr	�
write_rsrc�s
zBinHex.write_rsrccCs�|jdkrdSzp|jtkr2|j�n|jtkrPtd��n|jdkrxtd|jf��n|j�Wdd|_|j}|`|j�XdS)NzClose at the wrong timerz$Incorrect resource-datasize, diff=%r)rErQrRrrBrLr,r*)rr,rrr	r*�s
		zBinHex.closeN)rrrrrCrKrLr)rRrSr*rrrr	r<�s
r<cCs�t|�}t||�}tj|d�}x*|jd�}|sIPn|j|�q0W|j�|j�t|d�}x*|jd�}|s�Pn|j	|�q�W|j�|j�dS)zEbinhex(infilename, outfilename): create binhex-encoded copy of a fileri�N)
r%r<rrrr)rRr*r&rS)�inp�outr r,�ifprNrrr	r�s$


c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�_Hqxdecoderenginez*Read data via the decoder in 4-byte chunkscCs||_d|_dS)Nr)rV�eof)rrVrrr	rs	z_Hqxdecoderengine.__init__cCs�d}|}x�|dkr�|jr(|S|ddd}|jj|�}xjytj|�\}|_PWntjk
r�YnX|jjd�}|s�td��n||}qOW||}|t|�}|r|jrtd��qqW|S)z&Read at least wtd bytes (or until EOF)r(rrr0�r
zPremature EOF on binhex file)rXrVrr2Za2b_hqxZ
Incompleterr1)rZtotalwtdZdecdata�wtdr"Z
decdatacur�newdatarrr	rs,	
z_Hqxdecoderengine.readcCs|jj�dS)N)rVr*)rrrr	r*&sz_Hqxdecoderengine.closeN)rrrr7rrr*rrrr	rW�s rWc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_RledecoderenginezRead data via the RLE-codercCs(||_d|_d|_d|_dS)Nr(r)rV�
pre_buffer�post_bufferrX)rrVrrr	r,s			z_Rledecoderengine.__init__cCs_|t|j�kr2|j|t|j��n|jd|�}|j|d�|_|S)N)r1r^�_fill)rrZ�rvrrr	r2s
z_Rledecoderengine.readcCsH|j|jj|d�|_|jjrU|jtj|j�|_d|_dSt|j�}|jdd�tdtkr�|d}nv|jdd�tkr�|d}nP|jd	d�tdkr�|d}n&|jd
d�tkr�n
|d}|jtj|jd|��|_|j|d�|_dS)NrYr(r0sr
r���������rcrb)	r]rVrrXr^r2Z
rledecode_hqxr1�RUNCHAR)rrZ�markrrr	r_9s& 	
!



 z_Rledecoderengine._fillcCs|jj�dS)N)rVr*)rrrr	r*\sz_Rledecoderengine.closeN)rrrr7rrr_r*rrrr	r\)s
#r\c@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�HexBincCs�t|t�r$tj|d�}nxJ|jd�}|sKtd��n|dkr]q'n|dkr'Pq'q'Wt|�}t|�|_d|_	|j
�dS)Nrr
zNo binhex data founds
�:r)r>r?rrrrrWr\rVr@�_readheader)rrVZchZhqxifprrr	r`s	zHexBin.__init__cCs.|jj|�}tj||j�|_|S)N)rVrr2rPr@)rr1r"rrr	�_readvszHexBin._readcCsntjd|jjd��dd@}|jd@|_||jkratd|j|f��nd|_dS)Nz>hrri��zCRC error, computed %x, read %x)rI�unpackrVrr@r)rZfilecrcrrr	�	_checkcrc{s&zHexBin._checkcrccCs	|jd�}|jt|��}|jd�}|j�|dd�}|dd�}tjd|dd��d}tjd	|dd
��d|_tjd	|d
d��d|_||_t�|_||j_	||j_
||j_t|_
dS)Nr
rYr��	z>h�rz>l��rlrmrnrorp)ri�ordrkrIrjrArB�FNamerrr
rrDrE)rr1Zfname�rest�typeZcreator�flagsrrr	rh�s
 ##	zHexBin._readheadercGs�|jtkrtd��n|rC|d}t||j�}n	|j}d}x3t|�|kr�||j|t|��}qUW|j||_|S)NzRead data at wrong timerr()rErDr�minrAr1ri)r�nr`rrr	r�s
	!zHexBin.readcCsS|jtkrtd��n|jr<|j|j�}n|j�t|_dS)Nzclose_data at wrong time)rErDrrArirkrQ)r�dummyrrr	rR�s	
zHexBin.close_datacGs�|jtkr|j�n|jtkr:td��n|r_|d}t||j�}n	|j}|j||_|j|�S)Nz Read resource data at wrong timer)rErDrRrQrrvrBri)rrwrrr	�	read_rsrc�s

	zHexBin.read_rsrccCs]|jdkrdSz,|jr4|j|j�}n|j�Wdd|_|jj�XdS)N)rErBryrkrVr*)rrxrrr	r*�s		zHexBin.closeN)rrrrrirkrhrrRryr*rrrr	rf_s

rfcCs�t|�}|j}|s'|j}ntj|d�}x*|jd�}|sUPn|j|�q<W|j�|j�|j	d�}|r�t
|d�}|j|�x*|j	d�}|s�Pn|j|�q�W|j�n|j�dS)z6hexbin(infilename, outfilename) - Decode binhexed filer=i�N)rfrrrrrrr)r*rRryr&)rTrUrVr r,rNrrr	r�s.	



)r7rrrIr2�__all__�	ExceptionrrDrQr9r.rdrr%r&r+r8r<rrWr\rfrrrrr	�<module>s,

&^*6h