ó
5Þ	Pc           @   s®  d  Z  d d l Z d d l Z d d l Z d d l Z d d d g Z d e f d „  ƒ  YZ e d ƒ \ Z	 Z
 Z d Z d	 Z e d
 ƒ Z y< d d l m Z m Z d d l m Z d „  Z d „  Z Wn@ e k
 rd d$ d „  ƒ  YZ d „  Z d d% d „  ƒ  YZ n Xd d& d „  ƒ  YZ d d' d „  ƒ  YZ d d( d „  ƒ  YZ d „  Z d d) d „  ƒ  YZ d d* d „  ƒ  YZ d d+ d  „  ƒ  YZ d! „  Z d" „  Z  e! d# k rªe  ƒ  n  d S(,   s‰   Macintosh binhex compression/decompression.

easy interface:
binhex(inputfilename, outputfilename)
hexbin(inputfilename, outputfilename)
iÿÿÿÿNt   binhext   hexbint   Errorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.7/binhex.pyR      s   i   i €  i@   i   (   t   FSSpect   FInfo(   t   openrfc         C   s   t  |  ƒ j ƒ  } t j j |  ƒ \ } } t |  d ƒ } | j d d ƒ | j ƒ  } t |  d ƒ } | j d d ƒ | j ƒ  } | | | | f S(   Nt   rbi    i   s   *rb(	   R   t   FSpGetFInfot   ost   patht   splitt   opent   seekt   tellR   (   t   namet   finfot   dirt   filet   fpt   dlent   rlen(    (    s   /usr/lib/python2.7/binhex.pyt   getfileinfo3   s    c         G   s*   | s d } n d | d } t  |  | ƒ S(   Ns   *rbt   *i    (   R   (   R   t   mode(    (    s   /usr/lib/python2.7/binhex.pyt   openrsrc?   s    	R   c           B   s   e  Z d  „  Z RS(   c         C   s   d |  _  d |  _ d |  _ d  S(   Ns   ????i    (   t   Typet   Creatort   Flags(   t   self(    (    s   /usr/lib/python2.7/binhex.pyt   __init__L   s    		(   R   R   R   (    (    (    s   /usr/lib/python2.7/binhex.pyR   K   s   c         C   sÖ   t  ƒ  } t |  ƒ } t |  ƒ j d ƒ } xF | D]5 } | j ƒ  r1 | d k  sb t | ƒ d k r1 Pq1 q1 Wd | _ | j d d ƒ | j ƒ  } | j ƒ  t	 j
 j |  ƒ \ } } | j d d d	 ƒ } | | | d f S(
   Ni   t    i   t   TEXTi    i   t   :t   -i   (   R   R   t   readt   isspacet   ordR   R   R   t   closeR
   R   R   t   replace(   R   R   R   t   datat   ct   dsizeR   R   (    (    s   /usr/lib/python2.7/binhex.pyR   Q   s    	+	
R   c           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         G   s   d  S(   N(    (   R   t   args(    (    s   /usr/lib/python2.7/binhex.pyR   c   s    c         G   s   d S(   Nt    (    (   R   R,   (    (    s   /usr/lib/python2.7/binhex.pyR$   f   s    c         G   s   d  S(   N(    (   R   R,   (    (    s   /usr/lib/python2.7/binhex.pyt   writei   s    c         C   s   d  S(   N(    (   R   (    (    s   /usr/lib/python2.7/binhex.pyR'   l   s    (   R   R   R   R$   R.   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyR   b   s   			t   _Hqxcoderenginec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s(   Write data to the coder in 3-byte chunksc         C   s,   | |  _  d |  _ d |  _ t d |  _ d  S(   NR-   i   (   t   ofpR)   t   hqxdatat   LINELENt   linelen(   R   R0   (    (    s   /usr/lib/python2.7/binhex.pyR   r   s    			c         C   s~   |  j  | |  _  t |  j  ƒ } | d d } |  j  |  } |  j  | |  _  | sT d  S|  j t j | ƒ |  _ |  j d ƒ d  S(   Ni   i    (   R)   t   lenR1   t   binasciit   b2a_hqxt   _flush(   R   R)   t   datalent   todo(    (    s   /usr/lib/python2.7/binhex.pyR.   x   s    c         C   s—   d } xZ | t  |  j ƒ |  j k rb | |  j } |  j j |  j | | !d ƒ t |  _ | } q	 W|  j | |  _ | r“ |  j j |  j d ƒ n  d  S(   Ni    s   
s   :
(   R4   R1   R3   R0   R.   R2   (   R   t   forcet   firstt   last(    (    s   /usr/lib/python2.7/binhex.pyR7   ƒ   s    	
c         C   sL   |  j  r( |  j t j |  j  ƒ |  _ n  |  j d ƒ |  j j ƒ  |  ` d  S(   Ni   (   R)   R1   R5   R6   R7   R0   R'   (   R   (    (    s   /usr/lib/python2.7/binhex.pyR'   Ž   s
    	(   R   R   t   __doc__R   R.   R7   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyR/   o   s
   			t   _Rlecoderenginec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s4   Write data to the RLE-coder in suitably large chunksc         C   s   | |  _  d |  _ d  S(   NR-   (   R0   R)   (   R   R0   (    (    s   /usr/lib/python2.7/binhex.pyR   ™   s    	c         C   sX   |  j  | |  _  t |  j  ƒ t k  r) d  St j |  j  ƒ } |  j j | ƒ d |  _  d  S(   NR-   (   R)   R4   t   REASONABLY_LARGER5   t   rlecode_hqxR0   R.   (   R   R)   t   rledata(    (    s   /usr/lib/python2.7/binhex.pyR.      s    c         C   sE   |  j  r. t j |  j  ƒ } |  j j | ƒ n  |  j j ƒ  |  ` d  S(   N(   R)   R5   R@   R0   R.   R'   (   R   RA   (    (    s   /usr/lib/python2.7/binhex.pyR'   ¥   s
    	(   R   R   R=   R   R.   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyR>   –   s   		t   BinHexc           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c   	      C   sº   | \ } } } } t  | ƒ t  d ƒ k rB | } t | d ƒ } n  | j d ƒ t | ƒ } t | ƒ |  _ d |  _ | d  k r‹ t ƒ  } n  | |  _	 | |  _
 |  j | | ƒ t |  _ d  S(   NR-   t   ws0   (This file must be converted with BinHex 4.0)

:i    (   t   typeR   R.   R/   R>   R0   t   crct   NoneR   R   R   t
   _writeinfot   _DID_HEADERt   state(	   R   t   name_finfo_dlen_rlenR0   R   R   R   R   t   ofnamet   hqxer(    (    s   /usr/lib/python2.7/binhex.pyR   ­   s    			c   	      C   s¥   t  | ƒ } | d k r$ t d ‚ n  t | ƒ | d } | j | j } t j d | j ƒ } t j d |  j |  j	 ƒ } | | | | } |  j
 | ƒ |  j ƒ  d  S(   Ni?   s   Filename too longt    s   >hs   >ii(   R4   R   t   chrR   R   t   structt   packR   R   R   t   _writet	   _writecrc(	   R   R   R   t   nlt   dt   d2t   d3t   d4t   info(    (    s   /usr/lib/python2.7/binhex.pyRG   ½   s    c         C   s,   t  j | |  j ƒ |  _ |  j j | ƒ d  S(   N(   R5   t   crc_hqxRE   R0   R.   (   R   R)   (    (    s   /usr/lib/python2.7/binhex.pyRQ   Ë   s    c         C   sJ   |  j  d k  r d } n d } |  j j t j | |  j  ƒ ƒ d |  _  d  S(   Ni    s   >hs   >H(   RE   R0   R.   RO   RP   (   R   t   fmt(    (    s   /usr/lib/python2.7/binhex.pyRR   Ï   s
    	c         C   sB   |  j  t k r t d ‚ n  |  j t | ƒ |  _ |  j | ƒ d  S(   Ns   Writing data at the wrong time(   RI   RH   R   R   R4   RQ   (   R   R)   (    (    s   /usr/lib/python2.7/binhex.pyR.   Ù   s    c         C   s<   |  j  d k r% t d |  j f ‚ n  |  j ƒ  t |  _ d  S(   Ni    s   Incorrect data size, diff=%r(   R   R   R   RR   t	   _DID_DATARI   (   R   (    (    s   /usr/lib/python2.7/binhex.pyt
   close_dataß   s    
c         C   s^   |  j  t k  r |  j ƒ  n  |  j  t k r7 t d ‚ n  |  j t | ƒ |  _ |  j | ƒ d  S(   Ns'   Writing resource data at the wrong time(   RI   R[   R\   R   R   R4   RQ   (   R   R)   (    (    s   /usr/lib/python2.7/binhex.pyt
   write_rsrcå   s    c         C   s†   |  j  t k  r |  j ƒ  n  |  j  t k r7 t d ‚ n  |  j d k r\ t d |  j f ‚ n  |  j ƒ  |  j j ƒ  d  |  _  |  ` d  S(   Ns   Close at the wrong timei    s$   Incorrect resource-datasize, diff=%r(	   RI   R[   R\   R   R   RR   R0   R'   RF   (   R   (    (    s   /usr/lib/python2.7/binhex.pyR'   í   s    
	(
   R   R   R   RG   RQ   RR   R.   R\   R]   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyRB   ¬   s   				
			c         C   s½   t  |  ƒ } t | | ƒ } t |  d ƒ } x) | j d ƒ } | sF Pn  | j | ƒ q- | j ƒ  | j ƒ  t |  d ƒ } x) | j d ƒ } | s• Pn  | j | ƒ q| | j ƒ  | j ƒ  d S(   s@   (infilename, outfilename) - Create binhex-encoded copy of a fileR   i ô N(	   R   RB   R   R$   R.   R\   R'   R   R]   (   t   inpt   outR   R0   t   ifpRT   (    (    s   /usr/lib/python2.7/binhex.pyR    ú   s$     

 
t   _Hqxdecoderenginec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s*   Read data via the decoder in 4-byte chunksc         C   s   | |  _  d |  _ d  S(   Ni    (   R`   t   eof(   R   R`   (    (    s   /usr/lib/python2.7/binhex.pyR     s    	c         C   só   d } | } xà | d k rî |  j  r( | S| d d d } |  j j | ƒ } xe y t j | ƒ \ } |  _  PWn t j k
 r‚ n X|  j j d ƒ } | s§ t d ‚ n  | | } qO | | } | t | ƒ } | r |  j  r t d ‚ q q W| S(   s&   Read at least wtd bytes (or until EOF)R-   i    i   i   i   i   s   Premature EOF on binhex file(   Rb   R`   R$   R5   t   a2b_hqxt
   IncompleteR   R4   (   R   t   totalwtdt   decdatat   wtdR)   t
   decdatacurt   newdata(    (    s   /usr/lib/python2.7/binhex.pyR$     s.    	 	
c         C   s   |  j  j ƒ  d  S(   N(   R`   R'   (   R   (    (    s   /usr/lib/python2.7/binhex.pyR'   9  s    (   R   R   R=   R   R$   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyRa     s   		"t   _Rledecoderenginec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s   Read data via the RLE-coderc         C   s(   | |  _  d |  _ d |  _ d |  _ d  S(   NR-   i    (   R`   t
   pre_buffert   post_bufferRb   (   R   R`   (    (    s   /usr/lib/python2.7/binhex.pyR   ?  s    			c         C   sS   | t  |  j ƒ k r2 |  j | t  |  j ƒ ƒ n  |  j |  } |  j | |  _ | S(   N(   R4   Rl   t   _fill(   R   Rg   t   rv(    (    s   /usr/lib/python2.7/binhex.pyR$   E  s
    c         C   s$  |  j  |  j j | d ƒ |  _  |  j j rU |  j t j |  j  ƒ |  _ d |  _  d  St |  j  ƒ } |  j  d t d t k rŒ | d } nd |  j  d t k r¬ | d } nD |  j  d t d k rÐ | d } n  |  j  d t k ræ n
 | d	 } |  j t j |  j  |  ƒ |  _ |  j  | |  _  d  S(
   Ni   R-   iýÿÿÿRM   i   iÿÿÿÿi   iþÿÿÿi   (	   Rk   R`   R$   Rb   Rl   R5   t   rledecode_hqxR4   t   RUNCHAR(   R   Rg   t   mark(    (    s   /usr/lib/python2.7/binhex.pyRm   L  s&     	
c         C   s   |  j  j ƒ  d  S(   N(   R`   R'   (   R   (    (    s   /usr/lib/python2.7/binhex.pyR'   o  s    (   R   R   R=   R   R$   Rm   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyRj   <  s
   			#t   HexBinc           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   s½   t  | ƒ t  d ƒ k r' t | ƒ } n  xa | j d ƒ } | sK t d ‚ n  | d k r] q* n  | d k rm Pn  | d k r* | j ƒ  } q* q* t | ƒ } t | ƒ |  _ d |  _ |  j	 ƒ  d  S(   NR-   i   s   No binhex data founds   R"   s   
i    (
   RD   R   R$   R   t   readlineRa   Rj   R`   RE   t   _readheader(   R   R`   t   cht   dummyt   hqxifp(    (    s   /usr/lib/python2.7/binhex.pyR   s  s     	c         C   s.   |  j  j | ƒ } t j | |  j ƒ |  _ | S(   N(   R`   R$   R5   RY   RE   (   R   R4   R)   (    (    s   /usr/lib/python2.7/binhex.pyt   _read‹  s    c         C   sk   t  j d |  j j d ƒ ƒ d d @} |  j d @|  _ | |  j k r^ t d |  j | f ‚ n  d |  _ d  S(   Ns   >hi   i    iÿÿ  s   CRC error, computed %x, read %x(   RO   t   unpackR`   R$   RE   R   (   R   t   filecrc(    (    s   /usr/lib/python2.7/binhex.pyt	   _checkcrc  s    &c         C   sú   |  j  d ƒ } |  j  t | ƒ ƒ } |  j  d ƒ } |  j ƒ  | d d !} | d d !} t j d | d d !ƒ d } t j d	 | d d
 !ƒ d |  _ t j d	 | d
 d !ƒ d |  _ | |  _ t ƒ  |  _ | |  j _	 | |  j _
 | |  j _ t |  _ d  S(   Ni   i   i   i   i	   s   >hi   i    s   >li   i   i   i	   i   i   i   (   Rx   R&   R{   RO   Ry   R   R   t   FNameR   R   R   R   RH   RI   (   R   R4   t   fnamet   restRD   t   creatort   flags(    (    s   /usr/lib/python2.7/binhex.pyRt   š  s    
  	c         G   s™   |  j  t k r t d ‚ n  | r@ | d } t | |  j ƒ } n	 |  j } d } x3 t | ƒ | k  r„ | |  j | t | ƒ ƒ } qR W|  j | |  _ | S(   Ns   Read data at wrong timei    R-   (   RI   RH   R   t   minR   R4   Rx   (   R   t   nRn   (    (    s   /usr/lib/python2.7/binhex.pyR$   ®  s    
	!c         C   sP   |  j  t k r t d ‚ n  |  j r9 |  j |  j ƒ } n  |  j ƒ  t |  _  d  S(   Ns   close_data at wrong time(   RI   RH   R   R   Rx   R{   R[   (   R   Rv   (    (    s   /usr/lib/python2.7/binhex.pyR\   ¼  s    	
c         G   s‚   |  j  t k r |  j ƒ  n  |  j  t k r7 t d ‚ n  | r\ | d } t | |  j ƒ } n	 |  j } |  j | |  _ |  j | ƒ S(   Ns    Read resource data at wrong timei    (   RI   RH   R\   R[   R   R   R   Rx   (   R   R‚   (    (    s   /usr/lib/python2.7/binhex.pyt	   read_rsrcÄ  s    
	c         C   sB   |  j  r |  j |  j  ƒ } n  |  j ƒ  t |  _ |  j j ƒ  d  S(   N(   R   Rƒ   R{   t	   _DID_RSRCRI   R`   R'   (   R   Rv   (    (    s   /usr/lib/python2.7/binhex.pyR'   Ñ  s
    	
	(
   R   R   R   Rx   R{   Rt   R$   R\   Rƒ   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyRr   r  s   			
				c         C   sî   t  |  ƒ } | j } | s' | j } n  t | d ƒ } x) | j d ƒ } | sR Pn  | j | ƒ q9 | j ƒ  | j ƒ  | j d ƒ } | rà t	 | d ƒ } | j | ƒ x) | j d ƒ } | sÃ Pn  | j | ƒ qª | j ƒ  n  | j ƒ  d S(   s0   (infilename, outfilename) - Decode binhexed filet   wbi ô N(
   Rr   R   R|   R   R$   R.   R'   R\   Rƒ   R   (   R^   R_   R`   R   R0   RT   (    (    s   /usr/lib/python2.7/binhex.pyR   Ø  s.    	 

 c          C   sD   t  j d }  t |  |  d ƒ t |  d |  d ƒ t  j d ƒ d  S(   Ni   s   .hqxs   .viahqx(   t   syst   argvR    R   t   exit(   R}   (    (    s   /usr/lib/python2.7/binhex.pyt   _testô  s    t   __main__(    (    (    (    (    (    (    (    ("   R=   R†   R
   RO   R5   t   __all__t	   ExceptionR   t   rangeRH   R[   R„   R?   R2   RN   Rp   t   Carbon.FileR   R   t   MacOSR   R   R   t   ImportErrorR/   R>   RB   R    Ra   Rj   Rr   R   R‰   R   (    (    (    s   /usr/lib/python2.7/binhex.pyt   <module>   s<   		'N	,6f		