o
    \h                     @  s   d dl mZ d dlmZ d dlmZ d dlmZ d dl	m
Z d dlmZ er,ddlmZ eefZd)ddZd*ddZd+ddZ	d,d-ddZ	d,d.d d!Zd/d0d#d$Zd/d1d%d&Zd2d'd(ZdS )3    )annotations)	b64decode)	b64encode)encodebytes)Error)TYPE_CHECKING   )Bufferflagsintreturnstrc                 C  s   | dksJ dS )Nr   fallback )r
   r   r   U/home/air/segue/gemini/backup/venv/lib/python3.10/site-packages/pybase64/_fallback.py_get_simd_name   s   r   c                   C  s   dS )Nr   r   r   r   r   r   _get_simd_path   s   r   sstr | Bufferbytes | bytearrayc                 C  s   t | trz| dW S  ty   d}t|d w t | tr!| S zt| }|js5| jj	dd}t
|| W S  tyM   d| jj	d}t|d w )Nasciiz4string argument should contain only ASCII charactersr   ': underlying buffer is not C-contiguousz<argument should be a bytes-like object or ASCII string, not )
isinstancer   encodeUnicodeEncodeError
ValueError_bytes_types
memoryviewc_contiguous	__class____name__BufferErrortobytes	TypeError)r   msgmvr   r   r   
_get_bytes   s,   




r&   NFaltcharsstr | Buffer | Nonevalidateboolbytesc                 C  s   t | } |durt |}|rYt| d dkrd}t|t| |dd}d}t| dkrKd}| d dkr7|d	7 }| d
 dkrA|d	7 }dt| d  | }|t|krWd}t||S t| |ddS )a  Decode bytes encoded with the standard Base64 alphabet.

    Argument ``s`` is a :term:`bytes-like object` or ASCII string to
    decode.

    Optional ``altchars`` must be a :term:`bytes-like object` or ASCII
    string of length 2 which specifies the alternative alphabet used instead
    of the '+' and '/' characters.

    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 :exc:`binascii.Error`.

    The result is returned as a :class:`bytes` object.

    A :exc:`binascii.Error` is raised if ``s`` is incorrectly padded.
    N   r   zIncorrect paddingF)r)   =   r      zNon-base64 digit found)r&   lenBinAsciiErrorbuiltin_decode)r   r'   r)   r$   resultexpected_lenpaddingr   r   r   r   /   s*   r   	bytearrayc                 C  s   t t| ||dS )a  Decode bytes encoded with the standard Base64 alphabet.

    Argument ``s`` is a :term:`bytes-like object` or ASCII string to
    decode.

    Optional ``altchars`` must be a :term:`bytes-like object` or ASCII
    string of length 2 which specifies the alternative alphabet used instead
    of the '+' and '/' characters.

    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 :exc:`binascii.Error`.

    The result is returned as a :class:`bytearray` object.

    A :exc:`binascii.Error` is raised if ``s`` is incorrectly padded.
    )r'   r)   )r7   r   )r   r'   r)   r   r   r   b64decode_as_bytearray_   s   r8   r	   c                 C  s@   t | }|js| jjdd}t||durt|}t| |S )a  Encode bytes using the standard Base64 alphabet.

    Argument ``s`` is a :term:`bytes-like object` to encode.

    Optional ``altchars`` must 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.

    The result is returned as a :class:`bytes` object.
    r   r   N)r   r   r   r    r!   r&   builtin_encode)r   r'   r%   r$   r   r   r   r   x   s   
r   c                 C  s   t | |dS )a  Encode bytes using the standard Base64 alphabet.

    Argument ``s`` is a :term:`bytes-like object` to encode.

    Optional ``altchars`` must 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.

    The result is returned as a :class:`str` object.
    r   )r   decode)r   r'   r   r   r   b64encode_as_string   s   r;   c                 C  s.   t | }|js| jjdd}t|t| S )a-  Encode bytes into a bytes object with newlines (b'\\n') inserted after
    every 76 bytes of output, and ensuring that there is a trailing newline,
    as per :rfc:`2045` (MIME).

    Argument ``s`` is a :term:`bytes-like object` to encode.

    The result is returned as a :class:`bytes` object.
    r   r   )r   r   r   r    r!   builtin_encodebytes)r   r%   r$   r   r   r   r      s
   	r   )r
   r   r   r   )r   r   )r   r   r   r   )NF)r   r   r'   r(   r)   r*   r   r+   )r   r   r'   r(   r)   r*   r   r7   )N)r   r	   r'   r(   r   r+   )r   r	   r'   r(   r   r   )r   r	   r   r+   )
__future__r   base64r   r3   r   r9   r   r<   binasciir   r2   typingr   _typingr	   r+   r7   r   r   r   r&   r8   r;   r   r   r   r   <module>   s&    


1