ó
EŢ	Pc           @   s­  d  Z  d d l Z d d l Z d d l Z d d d d d d d	 d
 d d d d d d g Z g  e d  D] Z e e  ^ qg Z d Z	 d   Z
 d d  Z d d  Z d   Z d   Z d   Z d   Z i  d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d8 d9 6d: d; 6d< d= 6d> d? 6d@ dA 6dB dC 6dD dE 6dF dG 6dH dI 6dJ dK 6dL dM 6dN dO 6dP dQ 6dR dS 6dT dU 6dV dW 6dX dY 6Z e j   Z e j   g  e D] \ Z Z e ^ qÍZ e g  e j   D] \ Z Z e e e  f ^ qő Z dZ   Z e d d[  Z d\   Z e d]  Z d^ Z  e  d; d3 Z! d_   Z" d`   Z# da   Z$ db   Z% dc   Z& dd   Z' e( de k rŠe&   n  d S(f   s/   RFC 3548: Base16, Base32, Base64 Data Encodingsi˙˙˙˙Nt   encodet   decodet   encodestringt   decodestringt	   b64encodet	   b64decodet	   b32encodet	   b32decodet	   b16encodet	   b16decodet   standard_b64encodet   standard_b64decodet   urlsafe_b64encodet   urlsafe_b64decodei   t    c         C   sJ   t  } x* | j   D] \ } } | | t |  <q W|  j d j |   S(   NR   (   t   _translationt   itemst   ordt	   translatet   join(   t   st   altcharst   translationt   kt   v(    (    s   /usr/lib/python2.7/base64.pyt
   _translate    s    c         C   sF   t  j |   d  } | d k	 rB t | i | d d 6| d d 6 S| S(   sl  Encode a string using Base64.

    s is the string to encode.  Optional altchars must be a string of at least
    length 2 (additional characters are ignored) which specifies an
    alternative alphabet for the '+' and '/' characters.  This allows an
    application to e.g. generate url or filesystem safe Base64 strings.

    The encoded string is returned.
    i˙˙˙˙i    t   +i   t   /N(   t   binasciit
   b2a_base64t   NoneR   (   R   R   t   encoded(    (    s   /usr/lib/python2.7/base64.pyR   *   s    #c         C   sn   | d k	 r4 t |  i d | d 6d | d 6 }  n  y t j |   SWn" t j k
 ri } t |   n Xd S(   s  Decode a Base64 encoded string.

    s is the string to decode.  Optional altchars must be a string of at least
    length 2 (additional characters are ignored) which specifies the
    alternative alphabet used instead of the '+' and '/' characters.

    The decoded string is returned.  A TypeError is raised if s were
    incorrectly padded or if there are non-alphabet characters present in the
    string.
    R   i    R   i   N(   R   R   R   t
   a2b_base64t   Errort	   TypeError(   R   R   t   msg(    (    s   /usr/lib/python2.7/base64.pyR   ;   s    (c         C   s
   t  |   S(   sy   Encode a string using the standard Base64 alphabet.

    s is the string to encode.  The encoded string is returned.
    (   R   (   R   (    (    s   /usr/lib/python2.7/base64.pyR
   O   s    c         C   s
   t  |   S(   s  Decode a string encoded with the standard Base64 alphabet.

    s is the string to decode.  The decoded string is returned.  A TypeError
    is raised if the string is incorrectly padded or if there are non-alphabet
    characters present in the string.
    (   R   (   R   (    (    s   /usr/lib/python2.7/base64.pyR   V   s    c         C   s   t  |  d  S(   sš   Encode a string using a url-safe Base64 alphabet.

    s is the string to encode.  The encoded string is returned.  The alphabet
    uses '-' instead of '+' and '_' instead of '/'.
    s   -_(   R   (   R   (    (    s   /usr/lib/python2.7/base64.pyR   _   s    c         C   s   t  |  d  S(   sD  Decode a string encoded with the standard Base64 alphabet.

    s is the string to decode.  The decoded string is returned.  A TypeError
    is raised if the string is incorrectly padded or if there are non-alphabet
    characters present in the string.

    The alphabet uses '-' instead of '+' and '_' instead of '/'.
    s   -_(   R   (   R   (    (    s   /usr/lib/python2.7/base64.pyR   g   s    	t   Ai    t   Ji	   t   Si   t   3i   t   Bi   t   Ki
   t   Ti   t   4i   t   Ci   t   Li   t   Ui   t   5i   t   Di   t   Mi   t   Vi   t   6i   t   Ei   t   Ni   t   Wi   t   7i   t   Fi   t   Oi   t   Xi   t   Gi   t   Pi   t   Yi   t   Hi   t   Qi   t   Zi   t   Ii   t   Ri   t   2i   c   	      C   s  g  } t  t |   d  \ } } | rF |  d d | 7}  | d 7} n  xŰ t |  D]Í } t j d |  | d | d d ! \ } } } | | d @d >7} | | d @d >7} | j t | d ?t | d	 ?d
 @t | d ?d
 @t | d ?t | d ?d
 @t | d ?d
 @t | d ?t | d
 @g  qS Wt j |  } | d k rK| d  d S| d k rc| d  d S| d k r{| d  d S| d k r| d  d S| S(   sc   Encode a string using Base32.

    s is the string to encode.  The encoded string is returned.
    i   t    i   s   !HHBi   i   i   i   i   i   i   i   i   iú˙˙˙s   ======iü˙˙˙s   ====iý˙˙˙s   ===i   i˙˙˙˙t   =(	   t   divmodt   lent   ranget   structt   unpackt   extendt   _b32tabt   EMPTYSTRINGR   (	   R   t   partst   quantat   leftovert   it   c1t   c2t   c3R   (    (    s   /usr/lib/python2.7/base64.pyR      s6    .c         C   s  t  t |   d  \ } } | r0 t d   n  | rV t |  i d d 6| d 6 }  n  | rk |  j   }  n  d } t j d |   } | rť t | j d   } | d k rť |  |  }  qť n  g  } d } d	 }	 x |  D] }
 t j	 |
  } | d k rt d
   n  | t |
 |	 >7} |	 d 8}	 |	 d k  rÔ | j t j d |   d } d	 }	 qÔ qÔ Wt j d |  } | d k rd } np | d k r| d  } nW | d k rł| d  } n> | d k rĚ| d  } n% | d k rĺ| d  } n t d   | j |  t j |  S(   sG  Decode a Base32 encoded string.

    s is the string to decode.  Optional casefold is a flag specifying whether
    a lowercase alphabet is acceptable as input.  For security purposes, the
    default is False.

    RFC 3548 allows for optional mapping of the digit 0 (zero) to the letter O
    (oh), and for optional mapping of the digit 1 (one) to either the letter I
    (eye) or letter L (el).  The optional argument map01 when not None,
    specifies which letter the digit 1 should be mapped to (when map01 is not
    None, the digit 0 is always mapped to the letter O).  For security
    purposes the default is None, so that 0 and 1 are not allowed in the
    input.

    The decoded string is returned.  A TypeError is raised if s were
    incorrectly padded or if there are non-alphabet characters present in the
    string.
    i   s   Incorrect paddingR9   t   0t   1i    s   (?P<pad>[=]*)$t   padi#   s   Non-base32 digit foundi   s   %010xR   i   i˙˙˙˙i   iţ˙˙˙i   iý˙˙˙i   iü˙˙˙N(   RF   RG   R"   R   t   uppert   ret   searcht   groupt   _b32revt   getR   t   appendR   t	   unhexlifyRM   R   (   R   t   casefoldt   map01RO   RP   t   padcharst   moRN   t   acct   shiftt   ct   valt   last(    (    s   /usr/lib/python2.7/base64.pyR   ą   sP     
	c         C   s   t  j |   j   S(   sc   Encode a string using Base16.

    s is the string to encode.  The encoded string is returned.
    (   R   t   hexlifyRX   (   R   (    (    s   /usr/lib/python2.7/base64.pyR   ű   s    c         C   sC   | r |  j    }  n  t j d |   r6 t d   n  t j |   S(   sw  Decode a Base16 encoded string.

    s is the string to decode.  Optional casefold is a flag specifying whether
    a lowercase alphabet is acceptable as input.  For security purposes, the
    default is False.

    The decoded string is returned.  A TypeError is raised if s were
    incorrectly padded or if there are non-alphabet characters present in the
    string.
    s	   [^0-9A-F]s   Non-base16 digit found(   RX   RY   RZ   R"   R   R_   (   R   R`   (    (    s   /usr/lib/python2.7/base64.pyR	     s
    iL   c         C   s   x t  r |  j t  } | s" Pn  xC t |  t k  rg |  j t t |   } | sZ Pn  | | 7} q% Wt j |  } | j |  q Wd S(   s   Encode a file.N(   t   Truet   readt
   MAXBINSIZERG   R   R   t   write(   t   inputt   outputR   t   nst   line(    (    s   /usr/lib/python2.7/base64.pyR      s    	c         C   sC   x< t  r> |  j   } | s Pn  t j |  } | j |  q Wd S(   s   Decode a file.N(   Rj   t   readlineR   R    Rm   (   Rn   Ro   Rq   R   (    (    s   /usr/lib/python2.7/base64.pyR   ,  s    	c         C   s]   g  } xG t  d t |   t  D]- } |  | | t !} | j t j |   q Wd j |  S(   s4   Encode a string into multiple lines of base-64 data.i    R   (   RH   RG   Rl   R^   R   R   R   (   R   t   piecesRQ   t   chunk(    (    s   /usr/lib/python2.7/base64.pyR   6  s
    c         C   s   t  j |   S(   s   Decode a string.(   R   R    (   R   (    (    s   /usr/lib/python2.7/base64.pyR   ?  s    c    	      C   sQ  d d l  }  d d l } y# | j |  j d d  \ } } WnD | j k
 r } |  j |  _ | GHd |  j d GH|  j d  n Xt } xj | D]b \ } } | d k r° t } n  | d	 k rĹ t } n  | d
 k rÚ t } n  | d k r t	   d Sq W| r:| d d k r:t
 | d d   } | | |  j  Wd QXn | |  j |  j  d S(   s   Small test programi˙˙˙˙Ni   t   deuts   usage: %s [-d|-e|-u|-t] [file|-]
        -d, -u: decode
        -e: encode (default)
        -t: encode and decode string 'Aladdin:open sesame'i    i   s   -es   -ds   -us   -tt   -t   rb(   t   syst   getoptt   argvt   errort   stderrt   stdoutt   exitR    R   t   test1t   opent   stdin(	   Rx   Ry   t   optst   argsR#   t   funct   ot   at   f(    (    s   /usr/lib/python2.7/base64.pyt   testF  s.    # 	 	 	  c          C   s5   d }  t  |   } t |  } |  Gt |  G| GHd  S(   Ns   Aladdin:open sesame(   R   R   t   repr(   t   s0t   s1t   s2(    (    s   /usr/lib/python2.7/base64.pyR   `  s    t   __main__()   t   __doc__RY   RI   R   t   __all__RH   t   _xt   chrR   RM   R   R   R   R   R
   R   R   R   t   _b32alphabetR   RL   t   sortR   R   t   dictt   longR\   R   t   FalseR   R   R	   t   MAXLINESIZERl   R    R   R   R   R   R   t   __name__(    (    (    s   /usr/lib/python2.7/base64.pyt   <module>   sZ   %	
					
7	*J			
					