Current File : //proc/thread-self/root/opt/alt/python39/lib64/python3.9/__pycache__/base64.cpython-39.pyc
a
���e�M�@sndZddlZddlZddlZgd�ZeefZdd�Zd@dd�Z dAd d
�Z
dd�Zd
d�Ze�
dd�Ze�
dd�Zdd�Zdd�ZdZdadadd�ZdBdd�Zdd�ZdCdd�ZdadadZdZdDd d!�Zddddd"�d#d$�Zddd%d&�d'd(�Zd)Z da!da"da#dEd*d+�Z$d,d-�Z%d.Z&e&d/d0Z'd1d2�Z(d3d4�Z)d5d6�Z*d7d8�Z+d9d:�Z,d;d<�Z-d=d>�Z.e/d?k�rje-�dS)FzDBase16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data encodings�N)�encode�decode�encodebytes�decodebytes� b64encode� b64decode� b32encode� b32decode� b16encode� b16decode� b85encode� b85decode� a85encode� a85decode�standard_b64encode�standard_b64decode�urlsafe_b64encode�urlsafe_b64decodecCsxt|t�r2z|�d�WSty0td��Yn0t|t�r@|Szt|���WStyrtd|j j
�d�Yn0dS)N�asciiz4string argument should contain only ASCII charactersz>argument should be a bytes-like object or ASCII string, not %r)�
isinstance�strr�UnicodeEncodeError�
ValueError�bytes_types�
memoryview�tobytes� TypeError� __class__�__name__��s�r!�+/opt/alt/python39/lib64/python3.9/base64.py�_bytes_from_decode_data"s
��r#cCsDtj|dd�}|dur@t|�dks.Jt|���|�t�d|��S|S)a*Encode the bytes-like object s using Base64 and return a bytes object.
Optional altchars should be a byte string of length 2 which specifies an
alternative alphabet for the '+' and '/' characters. This allows an
application to e.g. generate url or filesystem safe Base64 strings.
F)�newlineN��+/)�binascii�
b2a_base64�len�repr� translate�bytes� maketrans)r �altchars�encodedr!r!r"r3s
rFcCsft|�}|durBt|�}t|�dks0Jt|���|�t�|d��}|r\t�d|�s\t� d��t�
|�S)anDecode the Base64 encoded bytes-like object or ASCII string s.
Optional altchars must be a bytes-like object or ASCII string of length 2
which specifies the alternative alphabet used instead of the '+' and '/'
characters.
The result is returned as a bytes object. A binascii.Error is raised if
s is incorrectly padded.
If validate is False (the default), characters that are neither in the
normal base-64 alphabet nor the alternative alphabet are discarded prior
to the padding check. If validate is True, these non-alphabet characters
in the input result in a binascii.Error.
Nr%r&s[A-Za-z0-9+/]*={0,2}zNon-base64 digit found)r#r)r*r+r,r-�re� fullmatchr'�Error�
a2b_base64)r r.Zvalidater!r!r"rAs
rcCst|�S)zrEncode bytes-like object s using the standard Base64 alphabet.
The result is returned as a bytes object.
)rrr!r!r"rZsrcCst|�S)aQDecode bytes encoded with the standard Base64 alphabet.
Argument s is a bytes-like object or ASCII string to decode. The result
is returned as a bytes object. A binascii.Error is raised if the input
is incorrectly padded. Characters that are not in the standard alphabet
are discarded prior to the padding check.
)rrr!r!r"rasrr&s-_cCst|��t�S)z�Encode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument s is a bytes-like object to encode. The result is returned as a
bytes object. The alphabet uses '-' instead of '+' and '_' instead of
'/'.
)rr+�_urlsafe_encode_translationrr!r!r"rosrcCst|�}|�t�}t|�S)a�Decode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument s is a bytes-like object or ASCII string to decode. The result
is returned as a bytes object. A binascii.Error is raised if the input
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+�_urlsafe_decode_translationrrr!r!r"rxs
rs ABCDEFGHIJKLMNOPQRSTUVWXYZ234567cs>tdur,dd�tD���fdd��D�ad�t|t�sBt|���}t|�d}|rb|dd|}t�}tj }t}t
dt|�d�D]V}||||d�d�}|||d ?||d
?d@||d?d@||d@7}q�|d
kr�d|dd�<nF|dk�rd|dd�<n.|dk�r d|dd�<n|dk�r6d|dd�<t|�S)zKEncode the bytes-like object s using Base32 and return a bytes object.
NcSsg|]}t|f��qSr!�r,��.0�ir!r!r"�
<listcomp>��zb32encode.<locals>.<listcomp>csg|]}�D]}||�qqSr!r!�r8�a�b�Zb32tabr!r"r:�r;��r�big��i��
�s======i����r%s====����s===�����=���)�_b32tab2�_b32alphabetrrrrr)� bytearray�int�
from_bytes�ranger,)r �leftoverr/rQZb32tab2r9�cr!r?r"r�s<
��
�
rc
Cs�tdurdd�tt�D�at|�}t|�dr8t�d��|durvt|�}t|�dks`Jt|���|�t �
dd|��}|r�|��}t|�}|�d �}|t|�}t
�}t}td
t|�d�D]h}|||d�}d
} z|D]}
| d>||
} q�Wn t�yt�d�d�Yn0|| �dd
�7}q�|d�s8|dv�rBt�d��|�r�|�r�| d|K} | �dd
�}dd|d}|d|�|dd�<t |�S)aZDecode the Base32 encoded bytes-like object or ASCII string s.
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 result is returned as a bytes object. A binascii.Error is raised if
the input is incorrectly padded or if there are non-alphabet
characters present in the input.
NcSsi|]\}}||�qSr!r!)r8�k�vr!r!r"�
<dictcomp>�r;zb32decode.<locals>.<dictcomp>�zIncorrect paddingrFs01�OrKrr@zNon-base32 digit foundrB>rrFrHrJ��+���)�_b32rev� enumeraterNr#r)r'r2r*r+r,r-�upper�rstriprOrR�KeyError�to_bytes)
r �casefoldZmap01�lZpadchars�decodedZb32revr9Zquanta�accrTZlastrSr!r!r"r �sB
r cCst�|���S)zKEncode the bytes-like object s using Base16 and return a bytes object.
)r'Zhexlifyr_rr!r!r"r
�sr
cCs4t|�}|r|��}t�d|�r*t�d��t�|�S)a�Decode the Base16 encoded bytes-like object or ASCII string s.
Optional casefold is a flag specifying whether a lowercase alphabet is
acceptable as input. For security purposes, the default is False.
The result is returned as a bytes object. A binascii.Error is raised if
s is incorrectly padded or if there are non-alphabet characters present
in the input.
s [^0-9A-F]zNon-base16 digit found)r#r_r0�searchr'r2Z unhexlify)r rcr!r!r"r�s
rs<~s~>c s�t|t�st|���}t|�d}|r4|d|}t�dt|�d��|�}����fdd�|D�}|r�|s�|ddkr��dd |d<|dd|�|d<d
�|�S)NrJrAz!%dIcsPg|]H}�r|sdn6�r$|dkr$dn&�|d�|dd�|d�qS)�zi �yi�^ �Ui9r!)r8Zword��chars�chars2�foldnuls�
foldspacesr!r"r:!s�
�
�z_85encode.<locals>.<listcomp>rLrhrr@r;) rrrrr)�struct�StructZunpack�join) r>rlrm�padrnro�paddingZwords�chunksr!rkr"� _85encodes
�rv)ro�wrapcolrs�adobecs�tdur*dd�tdd�D�add�tD�at|tt|d|��|rHt���r�t|rVdnd �����fd
d�tdt����D�}|r�t|d�d�kr�|�d
�d�|��|r��t 7��S)a�Encode bytes-like object b using Ascii85 and return a bytes object.
foldspaces is an optional flag that uses the special short sequence 'y'
instead of 4 consecutive spaces (ASCII 0x20) as supported by 'btoa'. This
feature is not supported by the "standard" Adobe encoding.
wrapcol controls whether the output should have newline (b'\n') characters
added to it. If this is non-zero, each output line will be at most this
many characters long.
pad controls whether the input is padded to a multiple of 4 before
encoding. Note that the btoa implementation always pads.
adobe controls whether the encoded byte sequence is framed with <~ and ~>,
which is used by the Adobe implementation.
NcSsg|]}t|f��qSr!r6r7r!r!r"r:Dr;za85encode.<locals>.<listcomp>�!�vcSsg|]}tD]}||�qqSr!)� _a85charsr<r!r!r"r:Er;Tr%rFcsg|]}�||���qSr!r!r7��resultrwr!r"r:Ms�rrLr;�
)
�
_a85chars2rRr{rv� _A85START�maxr)�appendrr�_A85END)r>rorwrsrxrur!r|r"r/s$�
rs
)rorx�ignorecharsc Cs�t|�}|rH|�t�s$td�t���|�t�r<|dd�}n|dd�}t�d�j }g}|j
}g}|j
}|j} |dD]�}
d|
kr�dkr�nnj||
�t|�d kr�d
}|D]}
d||
d}q�z|||��Wntj
y�td�d�Yn0| �qv|
d
k�r|�rtd��|d�qv|�rF|
dk�rF|�r<td��|d�qv|
|v�rTqvqvtd|
��qvd�|�}dt|�}
|
�r�|d|
�}|S)a�Decode the Ascii85 encoded bytes-like object or ASCII string b.
foldspaces is a flag that specifies whether the 'y' short sequence should be
accepted as shorthand for 4 consecutive spaces (ASCII 0x20). This feature is
not supported by the "standard" Adobe encoding.
adobe controls whether the input sequence is in Adobe Ascii85 format (i.e.
is framed with <~ and ~>).
ignorechars should be a byte string containing characters to ignore from the
input. This should only contain whitespace characters, and by default
contains all whitespace characters in ASCII.
The result is returned as a bytes object.
z1Ascii85 encoded byte sequences must end with {!r}r%���N�!Isuuuury�ur@rrjzAscii85 overflow�zzz inside Ascii85 5-tuples�yzy inside Ascii85 5-tuples zNon-Ascii85 digit found: %cr;rJ)r#�endswithr�r�format�
startswithr�rprq�packr��clearr)�errorrr)r>rorxr��packIreZdecoded_appendZcurrZcurr_appendZ
curr_clear�xrfr}rtr!r!r"rXsZ
��
rsU0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~cCs2tdur$dd�tD�add�tD�at|tt|�S)z�Encode bytes-like object b in base85 format and return a bytes object.
If pad is true, the input is padded with b'\0' so its length is a multiple of
4 bytes before encoding.
NcSsg|]}t|f��qSr!r6r7r!r!r"r:�r;zb85encode.<locals>.<listcomp>cSsg|]}tD]}||�qqSr!)� _b85charsr<r!r!r"r:�r;)�
_b85chars2�_b85alphabetr�rv)r>rsr!r!r"r�s rc
CsFtdur,dgdatt�D]\}}|t|<qt|�}t|�d}|d|}g}t�d�j}tdt|�d�D]�}|||d�}d}z|D]}|dt|}q�WnDt y�t|�D]&\}}t|dur�t
d||�d�q��Yn0z|�||��Wqntj�y t
d |�d�Yqn0qnd
�
|�} |�rB| d|�} | S)zqDecode the base85-encoded bytes-like object or ASCII string b
The result is returned as a bytes object.
N�r@�~r�rrjz#bad base85 character at position %dz+base85 overflow in hunk starting at byte %dr;)�_b85decr^r�r#r)rprqr�rRrrr�r�rr)
r>r9rTrt�outr��chunkrf�jr}r!r!r"r
�sH
����
r
�LrJrHcCsX|�t�}|sqTt|�tkr>|�tt|��}|s4q>||7}qt�|�}|�|�qdS)z1Encode a file; input and output are binary files.N)�read�
MAXBINSIZEr)r'r(�write)�input�outputr �ns�liner!r!r"r�s
rcCs(|��}|sq$t�|�}|�|�qdS)z1Decode a file; input and output are binary files.N)�readliner'r3r�)r�r�r�r r!r!r"r�s
rc
Cs�zt|�}Wn:tyF}z"d|jj}t|�|�WYd}~n
d}~00|jdvrld|j|jjf}t|��|jdkr�d|j|jjf}t|��dS)Nz"expected bytes-like object, not %s)rTr>�Bz-expected single byte elements, not %r from %srFz(expected 1-D data, not %d-D data from %s)rrrrr��ndim)r �m�err�msgr!r!r"�_input_type_check�s
�
�r�cCsLt|�g}tdt|�t�D]$}|||t�}|�t�|��qd�|�S)zVEncode a bytestring into a bytes object containing multiple lines
of base-64 data.rr;)r�rRr)r�r�r'r(rr)r �piecesr9r�r!r!r"rsrcCst|�t�|�S)z8Decode a bytestring of base-64 data into a bytes object.)r�r'r3rr!r!r"rsrc
Cs6ddl}ddl}z|�|jdd�d�\}}WnR|jy�}z8|j|_t|�td|jd�|�d�WYd}~n
d}~00t}|D]@\}}|dkr�t}|dkr�t }|d kr�t }|d
kr�t
�dSq�|�r |ddk�r t|dd��}|||jj�Wd�n1�s0Yn||j
j|jj�dS)
zSmall main programrNrFZdeutz�usage: %s [-d|-e|-u|-t] [file|-]
-d, -u: decode
-e: encode (default)
-t: encode and decode string 'Aladdin:open sesame'r%z-ez-dz-uz-t�-�rb)�sys�getopt�argvr��stderr�stdout�print�exitrr�test�open�buffer�stdin) r�r�Zopts�argsr��func�or=�fr!r!r"�mains(� 0r�cCsHd}tt|��t|�}tt|��t|�}tt|��||ksDJ�dS)NsAladdin:open sesame)r�r*rr)Zs0�s1�s2r!r!r"r�8sr��__main__)N)NF)FN)F)FFF)F)0�__doc__r0rpr'�__all__r,rOrr#rrrrr-r4r5rrrNrMr]rr r
rr{rr�r�rvrrr�r�r�r�rr
ZMAXLINESIZEr�rrr�rrr�r�rr!r!r!r"�<module>sZ
&
C
)H
-