Ñò
3mÈKc           @   s•   d  Z  d d k Z d d k Z d d k Z d d d g Z d e f d „  ƒ  YZ d d d „ Z d d d d	 „ Z	 d
 „  Z
 e d j o e
 ƒ  n d S(   sƒ   Implementation of the UUencode and UUdecode functions.

encode(in_file, out_file [,name, mode])
decode(in_file [, out_file, mode])
iÿÿÿÿNt   Errort   encodet   decodec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.6/uu.pyR    '   s   c         C   sƒ  |  d j o t  i }  n„ t |  t ƒ os | d
 j o t i i |  ƒ } n | d
 j o0 y t i |  ƒ i	 } WqŠ t
 j
 o qŠ Xn t |  d ƒ }  n | d j o t  i } n$ t | t ƒ o t | d ƒ } n | d
 j o
 d } n | d
 j o
 d } n | i d | d @| f ƒ |  i d ƒ } x= t | ƒ d j o) | i t i | ƒ ƒ |  i d ƒ } q5W| i d	 ƒ d
 S(   s   Uuencode filet   -t   rbt   wi¶  s   begin %o %s
iÿ  i-   i    s    
end
N(   t   syst   stdint
   isinstancet
   basestringt   Nonet   ost   patht   basenamet   statt   st_modet   AttributeErrort   opent   stdoutt   writet   readt   lent   binasciit   b2a_uu(   t   in_filet   out_filet   namet   modet   data(    (    s   /usr/lib/python2.6/uu.pyR   *   s4    	

 i    c         C   sÌ  |  d j o t  i }  n! t |  t ƒ o t |  ƒ }  n x¬ t o¤ |  i ƒ  } | p t d ƒ ‚ n | i d ƒ p q= n | i	 d d ƒ } t
 | ƒ d j oA | d d j o0 y t | d d	 ƒ PWqä t j
 o qä Xq= q= W| d j o; | d i ƒ  } t i i | ƒ o t d
 | ƒ ‚ q1n | d j o t | d d	 ƒ } n t } | d j o t  i } n] t | t ƒ oL t | d ƒ } y t i i | | ƒ Wn t j
 o n X| } t } n |  i ƒ  } x¼ | o´ | i ƒ  d j o¡ y t i | ƒ }	 Wnn t i j
 o_ }
 t | d ƒ d d @d d d } t i | |  ƒ }	 | p t  i i d |
 ƒ q~n X| i |	 ƒ |  i ƒ  } qàW| p t d ƒ ‚ n | o | i ƒ  n d S(   s   Decode uuencoded fileR   s'   No valid begin line found in input filet   begint    i   i   i    i   i   s"   Cannot overwrite existing file: %st   wbt   endi    i?   i   i   s   Warning: %s
s   Truncated input fileN(   R   R	   R
   R   R   t   Truet   readlineR    t
   startswitht   splitR   t   intt
   ValueErrorR   t   rstripR   R   t   existst   FalseR   t   chmodR   t   stripR   t   a2b_uut   ordt   stderrR   t   close(   R   R   R   t   quiett   hdrt	   hdrfieldst   openedt   fpt   sR   t   vt   nbytes(    (    s   /usr/lib/python2.6/uu.pyR   S   sf     $
 $c          C   sÍ  d d k  }  |  i d d ƒ } | i d d d d d	 d
 d t d d ƒ| i d d d d d	 d d t d d ƒ| i ƒ  \ } } t | ƒ d j o | i d ƒ t i d ƒ n t i	 } t i
 } t | ƒ d j o | d } n t | ƒ d j o | d } n | i o_ | i oD t | t ƒ o t | d ƒ } q]t i d Gd GHt i d ƒ n t | | ƒ n\ | i oD t | t ƒ o t | d ƒ } q¼t i d Gd GHt i d ƒ n t | | ƒ d S(   s   uuencode/uudecode main programiÿÿÿÿNt   usages'   usage: %prog [-d] [-t] [input [output]]s   -ds   --decodet   destR   t   helps   Decode (instead of encode)?t   defaultt   actiont
   store_trues   -ts   --textt   texts2   data is text, encoded format unix-compatible text?i   s   incorrect number of argumentsi   i    R   s   : cannot do -t to stdoutt   rs   : cannot do -t from stdin(   t   optparset   OptionParsert
   add_optionR+   t
   parse_argsR   t   errorR   t   exitR	   R   R   R@   R
   R   R   t   argvR   (   RB   t   parsert   optionst   argst   inputt   output(    (    s   /usr/lib/python2.6/uu.pyt   test”   s6    ((		


t   __main__(   t   __doc__R   R   R   t   __all__t	   ExceptionR    R   R   R   RN   R   (    (    (    s   /usr/lib/python2.6/uu.pyt   <module>   s   )A	%