ó
¬«Y]c           @   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   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 @| f ƒ |  j d ƒ } x; t | ƒ d k r€| j t j | ƒ ƒ |  j d ƒ } qFW| j d	 ƒ Wd
 x | D] } | j ƒ  q™WXd
 S(   s   Uuencode filet   -t   rbt   wbi¶  s   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   writet   readt   lent   binasciit   b2a_uut   close(   t   in_filet   out_filet   namet   modet   opened_filest   datat   f(    (    s   lib/python2.7/uu.pyR   *   s>    		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   lib/python2.7/uu.pyR   Z   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   R@   R
   R   R   t   argvR   (   RC   t   parsert   optionst   argst   inputt   output(    (    s   lib/python2.7/uu.pyt   testž   s6    ((					t   __main__(   t   __doc__R   R   R   t   __all__t	   ExceptionR    R   R   R   RP   R   (    (    (    s   lib/python2.7/uu.pyt   <module>   s   0D	%