
    ,h                         d dl Z d dlZd dlmZ ddlmZ er d dlmZmZ  edd      Z G d	 d
ee         Z	 G d d      Z
 G d d      Zy)    N)TYPE_CHECKING   )DecodeError)ProtocolTypeVar	_T_contraT)contravariantc                       e Zd ZdedefdZy)SupportsWrite_SupportsWrite__breturnc                      y N )selfr   s     [/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/python_multipart/decoders.pywritezSupportsWrite.write   s        N)__name__
__module____qualname__r   objectr   r   r   r   r   r      s    6Y666r   r   c                   D    e Zd ZdZd
dZdedefdZddZddZ	de
fd	Zy)Base64Decodera  This object provides an interface to decode a stream of Base64 data.  It
    is instantiated with an "underlying object", and whenever a write()
    operation is performed, it will decode the incoming data as Base64, and
    call write() on the underlying object.  This is primarily used for decoding
    form data encoded as Base64, but can be used for other purposes::

        from python_multipart.decoders import Base64Decoder
        fd = open("notb64.txt", "wb")
        decoder = Base64Decoder(fd)
        try:
            decoder.write("Zm9vYmFy")       # "foobar" in Base64
            decoder.finalize()
        finally:
            decoder.close()

        # The contents of "notb64.txt" should be "foobar".

    This object will also pass all finalize() and close() calls to the
    underlying object, if the underlying object supports them.

    Note that this class maintains a cache of base64 chunks, so that a write of
    arbitrary size can be performed.  You must call :meth:`finalize` on this
    object after all writes are completed to ensure that all data is flushed
    to the underlying object.

    :param underlying: the underlying object to pass writes to
    r   Nc                 0    t               | _        || _        y r   )	bytearraycache
underlyingr   r   s     r   __init__zBase64Decoder.__init__2   s    [
$r   datac                    t        | j                        dkD  r| j                  |z   }t        |      dz  dz  }|d| }t        |      dkD  r1	 t        j                  |      }| j                  j                  |       t        |      dz  }|dkD  r|| d | j                  dd t        |      S d| j                  dd t        |      S # t        j
                  $ r t        d      w xY w)a)  Takes any input data provided, decodes it as base64, and passes it
        on to the underlying object.  If the data provided is invalid base64
        data, then this method will raise
        a :class:`python_multipart.exceptions.DecodeError`

        :param data: base64 data to decode
        r      Nz=There was an error raised while decoding base64-encoded data.r   )	lenr   base64	b64decodebinasciiErrorr   r   r   )r   r!   
decode_lenvaldecodedremaining_lens         r   r   zBase64Decoder.write6   s     tzz?Q::$D $i1n)
;J s8a<c **3/ OO!!'* D	A1 -1DJJqM
 4y  DJJqM 4y >> c!"abbcs   C C'c                 f    t        | j                  d      r| j                  j                          yyzrClose this decoder.  If the underlying object has a `close()`
        method, this function will call it.
        closeNhasattrr   r/   r   s    r   r/   zBase64Decoder.closeZ   '     4??G,OO!!# -r   c                     t        | j                        dkD  r!t        dt        | j                        z        t        | j                  d      r| j                  j                          yy)a[  Finalize this object.  This should be called when no more data
        should be written to the stream.  This function can raise a
        :class:`python_multipart.exceptions.DecodeError` if there is some remaining
        data in the cache.

        If the underlying object has a `finalize()` method, this function will
        call it.
        r   zQThere are %d bytes remaining in the Base64Decoder cache when finalize() is calledfinalizeN)r$   r   r   r1   r   r5   r2   s    r   r5   zBase64Decoder.finalizea   s[     tzz?Qcfijnjtjtfuu  4??J/OO$$& 0r   c                 N    | j                   j                   d| j                  dS Nz(underlying=)	__class__r   r   r2   s    r   __repr__zBase64Decoder.__repr__r   %    ..))*,t6IKKr   r   zSupportsWrite[bytes]r   Nr   Nr   r   r   __doc__r    bytesintr   r/   r5   strr;   r   r   r   r   r      s8    8%"% "C "H$'"L# Lr   r   c                   D    e Zd ZdZd
dZdedefdZddZddZ	de
fd	Zy)QuotedPrintableDecodera  This object provides an interface to decode a stream of quoted-printable
    data.  It is instantiated with an "underlying object", in the same manner
    as the :class:`python_multipart.decoders.Base64Decoder` class.  This class behaves
    in exactly the same way, including maintaining a cache of quoted-printable
    chunks.

    :param underlying: the underlying object to pass writes to
    r   Nc                      d| _         || _        y )Nr   )r   r   r   s     r   r    zQuotedPrintableDecoder.__init__   s    
$r   r!   c                 8   t        | j                        dkD  r| j                  |z   }|dd j                  d      dk7  r|dd |dd }}n|}d}t        |      dkD  r.| j                  j	                  t        j                  |             || _        t        |      S )zTakes any input data provided, decodes it as quoted-printable, and
        passes it on to the underlying object.

        :param data: quoted-printable data to decode
        r   N   =r   )r$   r   findr   r   r'   a2b_qp)r   r!   encrests       r   r   zQuotedPrintableDecoder.write   s     tzz?Q::$D
 9>>$2%Sb	49CCD s8a<OO!!(//#"67 
4yr   c                 f    t        | j                  d      r| j                  j                          yyr.   r0   r2   s    r   r/   zQuotedPrintableDecoder.close   r3   r   c                    t        | j                        dkD  r?| j                  j                  t	        j
                  | j                               d| _        t        | j                  d      r| j                  j                          yy)al  Finalize this object.  This should be called when no more data
        should be written to the stream.  This function will not raise any
        exceptions, but it may write more data to the underlying object if
        there is data remaining in the cache.

        If the underlying object has a `finalize()` method, this function will
        call it.
        r   r   r5   N)r$   r   r   r   r'   rL   r1   r5   r2   s    r   r5   zQuotedPrintableDecoder.finalize   s_     tzz?QOO!!(//$**"=>DJ 4??J/OO$$& 0r   c                 N    | j                   j                   d| j                  dS r7   r9   r2   s    r   r;   zQuotedPrintableDecoder.__repr__   r<   r   r=   r>   r?   r   r   r   rE   rE   v   s7    %% C 6$'$L# Lr   rE   )r%   r'   typingr   
exceptionsr   r   r   r   r   r   rE   r   r   r   <module>rT      sQ        #(48I7+ 7^L ^LBCL CLr   