mò
­fIc           @   s™   d  Z  d k Z d k Z d k Z d k l 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])
N(   s
   StringTypet   Errort   encodet   decodec           B   s   t  Z RS(   N(   t   __name__t
   __module__(    (    (    t   /mit/python/lib/python2.4/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   in_filet   syst   stdint
   isinstancet
   StringTypet   namet   Nonet   ost   patht   basenamet   modet   statt   st_modet   AttributeErrort   opent   out_filet   stdoutt   writet   readt   strt   lent   binasciit   b2a_uu(   R	   R   R   R   R   (    (    R   R   +   s6     	

 i    c         C   s¢  |  d j o t i }  n! t |  t ƒ o t |  ƒ }  n x£ |  i ƒ  } | p t d ‚ n | d  d j o 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 o8 |
 d i ƒ  } t i i | ƒ o t d | ‚ q%n | d j o t |
 d d
 ƒ } n | d j o t i } nW t | t ƒ oF t | d ƒ } y t i i | | ƒ Wn t j
 o n X| } n |  i ƒ  } xÂ | oº | i ƒ  d j o§ y t i | ƒ } Wnt t i j
 oe }	 t | d	 ƒ d d @d d d } t i | |  ƒ } | p t i" i# d t$ |	 ƒ ƒ qln X| i# | ƒ |  i ƒ  } qÈW| p t d ‚ n d S(   s   Decode uuencoded fileR   i   s'   No valid begin line found in input filei   t   begint    i   i   i    i   s"   Cannot overwrite existing file: %st   wbt   endi    i?   i   s   Warning: %s
s   Truncated input fileN(%   R	   R
   R   R   R   R   t   readlinet   hdrR    t   splitt	   hdrfieldsR   t   intt
   ValueErrorR   R   t   rstripR   R   t   existsR   R   t   fpt   chmodR   t   st   stripR   t   a2b_uut   datat   vt   ordt   nbytest   quiett   stderrR   R   (   R	   R   R   R5   R4   R,   R1   R%   R.   R2   R'   (    (    R   R   T   s`       $
 $#c    
      C   sÿ  d k  } d }	 d } t i } t i } d } y# | i  t i	 d d ƒ \ } } Wn | i j
 o d } n X| p t | ƒ d j o/ d Gt i	 d Gd GHd GHd	 GHt i d ƒ n xB | D]: \ } }  | d
 j o
 d }	 n | d j o
 d } qÀ qÀ Wt | ƒ d j o | d } n t | ƒ d j o | d } n |	 o\ | oD t | t ƒ o t | d ƒ } q’t i	 d Gd GHt i d ƒ n t | | ƒ nY | oD t | t ƒ o t | d ƒ } qît i	 d Gd GHt i d ƒ n t | | ƒ d S(   s   uuencode/uudecode main programNi    i   t   dti   s   Usage:s   [-d] [-t] [input [output]]s     -d: Decode (in stead of encode)s6    -t: data is text, encoded format unix-compatible texts   -ds   -tR   s   : cannot do -t to stdoutt   rs   : cannot do -t from stdin(   t   getoptt   doptt   toptR
   R   t   inputR   t   outputt   okt   argvt   optlistt   argst   errorR   t   exitt   ot   aR   R   R   R   R   (
   RE   R@   RA   R>   R<   R;   RD   R=   R9   R:   (    (    R   t   test‘   sN     			#  
 t   __main__(   t   __doc__R   R   R
   t   typesR   t   __all__t	   ExceptionR    R   R   R   RF   R   (	   R   RJ   R   R
   RF   R    R   R   R   (    (    R   t   ?   s   			)=	-