ó
čžbc           @   sÝ  d  Z  d d l 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  ^ qs Z	 d Z
 d   Z d d  Z d d  Z d   Z d   Z e j d d  Z e j d 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/ 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 6dZ d[ 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 d\   Z e  d d]  Z! d^   Z" e  d_  Z# d` Z$ e$ d= d5 Z% da   Z& db   Z' dc   Z( dd   Z) de   Z* df   Z+ e, dg k rŮe*   n  d S(h   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   s@   t  j |   d  } | d k	 r< | j t j d | d    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˙˙˙˙s   +/i   N(   t   binasciit
   b2a_base64t   NoneR   t   stringt	   maketrans(   R   R   t   encoded(    (    s   /usr/lib/python2.7/base64.pyR   +   s    c         C   sh   | d k	 r. |  j t j | d  d   }  n  y t j |   SWn" t j k
 rc } 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 is
    incorrectly padded.  Characters that are neither in the normal base-64
    alphabet nor the alternative alphabet are discarded prior to the padding
    check.
    i   s   +/N(   R   R   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
   Q   s    c         C   s
   t  |   S(   s-  Decode a string encoded with the standard Base64 alphabet.

    Argument s is the string to decode.  The decoded string is returned.  A
    TypeError is raised if the string is incorrectly padded.  Characters that
    are not in the standard alphabet are discarded prior to the padding
    check.
    (   R   (   R   (    (    s   /usr/lib/python2.7/base64.pyR   X   s    s   +/s   -_c         C   s   t  |   j t  S(   sÔ   Encode a string using the URL- and filesystem-safe Base64 alphabet.

    Argument s is the string to encode.  The encoded string is returned.  The
    alphabet uses '-' instead of '+' and '_' instead of '/'.
    (   R   R   t   _urlsafe_encode_translation(   R   (    (    s   /usr/lib/python2.7/base64.pyR   e   s    c         C   s   t  |  j t   S(   sŚ  Decode a string using the URL- and filesystem-safe Base64 alphabet.

    Argument s is the string to decode.  The decoded string is returned.  A
    TypeError is raised if the string is incorrectly padded.  Characters that
    are not in the URL-safe base-64 alphabet, and are not a plus '+' or slash
    '/', are discarded prior to the padding check.

    The alphabet uses '-' instead of '+' and '_' instead of '/'.
    (   R   R   t   _urlsafe_decode_translation(   R   (    (    s   /usr/lib/python2.7/base64.pyR   m   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   s    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  | rX |  j t j d d |   }  n  | rm |  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 paddingt   01R;   i    s   (?P<pad>[=]*)$t   padi#   s   Non-base32 digit foundi   s   %010xR   i   i˙˙˙˙i   iţ˙˙˙i   iý˙˙˙i   iü˙˙˙N(   RG   RH   R"   R   R   R   t   uppert   ret   searcht   groupt   _b32revt   getR   t   appendR   t	   unhexlifyRN   R   (   R   t   casefoldt   map01RP   RQ   t   padcharst   moRO   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(   su  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 is
    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
   MAXBINSIZERH   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   3  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   (   RI   RH   Rl   R^   R   R   R   (   R   t   piecesRR   t   chunk(    (    s   /usr/lib/python2.7/base64.pyR   =  s
    c         C   s   t  j |   S(   s   Decode a string.(   R   R    (   R   (    (    s   /usr/lib/python2.7/base64.pyR   F  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   testM  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   g  s    t   __main__(-   t   __doc__RY   RJ   R   R   t   __all__RI   t   _xt   chrR   RN   R   R   R   R   R
   R   R   R$   R%   R   R   t   _b32alphabetR   RM   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>   s`   %	
		
		
7	*J			
					