ó
è¾bc           @   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 d Z d 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@   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   getfileinfo4   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__M   s    		(   R   R   R   (    (    (    s   /usr/lib/python2.7/binhex.pyR   L   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   R   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   d   s    c         G   s   d S(   Nt    (    (   R   R,   (    (    s   /usr/lib/python2.7/binhex.pyR$   g   s    c         G   s   d  S(   N(    (   R   R,   (    (    s   /usr/lib/python2.7/binhex.pyt   writej   s    c         C   s   d  S(   N(    (   R   (    (    s   /usr/lib/python2.7/binhex.pyR'   m   s    (   R   R   R   R$   R.   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyR   c   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   s   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.   y   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/   p   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 longs    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.pyRP   Ì   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.   RN   RO   (   R   t   fmt(    (    s   /usr/lib/python2.7/binhex.pyRQ   Ð   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   RP   (   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   RQ   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   RZ   R[   R   R   R4   RP   (   R   R)   (    (    s   /usr/lib/python2.7/binhex.pyt
   write_rsrcæ   s    c         C   s§   |  j  d  k r d  Szj |  j  t k  r2 |  j ƒ  n  |  j  t k rM t d ‚ n  |  j d k rr t d |  j f ‚ n  |  j ƒ  Wd  d  |  _  |  j } |  ` | j ƒ  Xd  S(   Ns   Close at the wrong timei    s$   Incorrect resource-datasize, diff=%r(	   RI   RF   RZ   R[   R   R   RQ   R0   R'   (   R   R0   (    (    s   /usr/lib/python2.7/binhex.pyR'   î   s    		(
   R   R   R   RG   RP   RQ   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- W| j ƒ  | j ƒ  t |  d ƒ } x* | j d ƒ } | s– Pn  | j | ƒ q} W| 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   ifpRS   (    (    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 | ƒ } xf y t j | ƒ \ } |  _  PWn t j k
 r‚ n X|  j j d ƒ } | s§ t d ‚ n  | | } qO W| | } | 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(   Ra   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'   ?  s    (   R   R   R=   R   R$   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyR`     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_bufferRa   (   R   R_   (    (    s   /usr/lib/python2.7/binhex.pyR   E  s    			c         C   sS   | t  |  j ƒ k r2 |  j | t  |  j ƒ ƒ n  |  j |  } |  j | |  _ | S(   N(   R4   Rk   t   _fill(   R   Rf   t   rv(    (    s   /usr/lib/python2.7/binhex.pyR$   K  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ýÿÿÿs    i   iÿÿÿÿi   iþÿÿÿi   (	   Rj   R_   R$   Ra   Rk   R5   t   rledecode_hqxR4   t   RUNCHAR(   R   Rf   t   mark(    (    s   /usr/lib/python2.7/binhex.pyRl   R  s&     	
c         C   s   |  j  j ƒ  d  S(   N(   R_   R'   (   R   (    (    s   /usr/lib/python2.7/binhex.pyR'   u  s    (   R   R   R=   R   R$   Rl   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyRi   B  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  xb | j d ƒ } | sK t d ‚ n  | d k r] q* n  | d k rm Pn  | d k r* | j ƒ  } q* q* Wt | ƒ } t | ƒ |  _ d |  _ |  j	 ƒ  d  S(   NR-   i   s   No binhex data founds   R"   s   
i    (
   RD   R   R$   R   t   readlineR`   Ri   R_   RE   t   _readheader(   R   R_   t   cht   dummyt   hqxifp(    (    s   /usr/lib/python2.7/binhex.pyR   y  s     	c         C   s.   |  j  j | ƒ } t j | |  j ƒ |  _ | S(   N(   R_   R$   R5   RX   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(   RN   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   (   Rw   R&   Rz   RN   Rx   R   R   t   FNameR   R   R   R   RH   RI   (   R   R4   t   fnamet   restRD   t   creatort   flags(    (    s   /usr/lib/python2.7/binhex.pyRs      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   Rw   (   R   t   nRm   (    (    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   Rw   Rz   RZ   (   R   Ru   (    (    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[   RZ   R   R€   R   Rw   (   R   R   (    (    s   /usr/lib/python2.7/binhex.pyt	   read_rsrcÊ  s    
	c         C   s]   |  j  d  k r d  Sz, |  j r4 |  j |  j ƒ } n  |  j ƒ  Wd  d  |  _  |  j j ƒ  Xd  S(   N(   RI   RF   R   R‚   Rz   R_   R'   (   R   Ru   (    (    s   /usr/lib/python2.7/binhex.pyR'   ×  s    		(
   R   R   R   Rw   Rz   Rs   R$   R[   R‚   R'   (    (    (    s   /usr/lib/python2.7/binhex.pyRq   x  s   			
				c         C   sð   t  |  ƒ } | j } | s' | j } n  t | d ƒ } x* | j d ƒ } | sR Pn  | j | ƒ q9 W| j ƒ  | j ƒ  | j d ƒ } | râ t	 | d ƒ } | j | ƒ x* | j d ƒ } | sÄ Pn  | j | ƒ q« W| j ƒ  n  | j ƒ  d S(   s0   (infilename, outfilename) - Decode binhexed filet   wbi ô N(
   Rq   R   R{   R   R$   R.   R'   R[   R‚   R   (   R]   R^   R_   R   R0   RS   (    (    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
   RN   R5   t   __all__t	   ExceptionR   RH   RZ   R?   R2   RM   Ro   t   Carbon.FileR   R   t   MacOSR   R   R   t   ImportErrorR/   R>   RB   R    R`   Ri   Rq   R   R‡   R   (    (    (    s   /usr/lib/python2.7/binhex.pyt   <module>   s>   		'S	,6j		