ó
č¾bc           @   s   d  Z  d d l Z d d l Z d d 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 k r 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.7/uu.pyR    '   s   c         C   sÖ  g  } z­|  d k r! t  j }  n t |  t  r© | d k rQ t j j |   } n  | d k r y t j |   j	 } Wq t
 k
 r q Xn  t |  d  }  | j |   n  | d k rĮ t  j } n. t | t  rļ t | d  } | j |  n  | d k rd } n  | d k rd } n  | j d d  } | j d d  } | j d	 | d
 @| f  |  j d  } x; t |  d k r¤| j t j |   |  j d  } qjW| j d  Wd x | D] } | j   q½WXd S(   s   Uuencode filet   -t   rbt   wbi¶  s   
s   \ns   s   \rs   begin %o %s
i’  i-   i    s    
end
N(   t   syst   stdint
   isinstancet
   basestringt   Nonet   ost   patht   basenamet   statt   st_modet   AttributeErrort   opent   appendt   stdoutt   replacet   writet   readt   lent   binasciit   b2a_uut   close(   t   in_filet   out_filet   namet   modet   opened_filest   datat   f(    (    s   /usr/lib/python2.7/uu.pyR   *   sB    		i    c         C   sŹ  g  } |  d k r t  j }  n+ t |  t  rI t |   }  | j |   n  z^x” t rļ |  j   } | sv t d   n  | j	 d  s qO n  | j
 d d  } t |  d k rO | d d k rO y t | d d	  PWqģ t k
 rč qģ XqO qO W| d k r4| d j   } t j j |  r4t d
 |   q4n  | d k rVt | d d	  } n  | d k rnt  j } n_ t | t  rĶt | d  } y t j j | |  Wn t k
 r¶n X| } | j |  n  |  j   } xµ | r| j   d k ry t j |  }	 Wnj t j k
 rs}
 t | d  d d @d d d } t j | |   }	 | stt  j j d |
  qtn X| j |	  |  j   } qÜW| s¦t d   n  Wd x | D] } | j   q±WXd 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: %sR   t   endi    i?   i   i   s   Warning: %s
s   Truncated input fileN(   R   R	   R
   R   R   R   t   Truet   readlineR    t
   startswitht   splitR   t   intt
   ValueErrorR   t   rstripR   R   t   existsR   t   chmodR   t   stripR   t   a2b_uut   ordt   stderrR   R   (   R   R   R    t   quietR!   t   hdrt	   hdrfieldst   fpt   sR"   t   vt   nbytesR#   (    (    s   /usr/lib/python2.7/uu.pyR   a   sf    	"$c          C   s½  d d l  }  |  j d d  } | j d d d d d	 d
 d t d d | j d d d d d	 d d t d d | j   \ } } t |  d k rÆ | j d  t j d  n  t j	 } t j
 } t |  d k rą | d } n  t |  d k r’ | d } n  | j rb| j rRt | t  r2t | d  } qRt j d Gd GHt j d  n  t | |  nW | j r¬t | t  rt | d  } q¬t j d Gd GHt j 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    t   ws   : cannot do -t to stdoutt   rs   : cannot do -t from stdin(   t   optparset   OptionParsert
   add_optiont   Falset
   parse_argsR   t   errorR   t   exitR	   R   R   RA   R
   R   R   t   argvR   (   RD   t   parsert   optionst   argst   inputt   output(    (    s   /usr/lib/python2.7/uu.pyt   test„   s6    ((					t   __main__(   t   __doc__R   R   R   t   __all__t	   ExceptionR    R   R   R   RQ   R   (    (    (    s   /usr/lib/python2.7/uu.pyt   <module>   s   7D	%