§
    sŠtjˆ  ã                   ót   — d Z ddlZddlZddlmZ dZ ej        de›de›d�¦  «        Z	d	Z
d
„ Zd„ Zde
fd„ZdS )z-Utilities for dealing with streamed requests.é    Né   )Ú
exceptionsz"[^"\\]*(?:\\.[^"\\]*)*"z;\s*(z|[^\s;=]+)\s*(?:=\s*(z|[^;]+))?\s*i   c                 óÈ   — t                                | ¦  «        D ]F}|                     ¦   «         \  }}|dk    r't          j                             |¦  «        d         c S ŒGd S )NÚfilenameé   )Ú_OPTION_HEADER_PIECE_REÚfinditerÚgroupsÚosÚpathÚsplit)Úcontent_dispositionÚmatchÚkÚvs       úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/requests_toolbelt/downloadutils/stream.pyÚ_get_filenamer      se   € Ý(×1Ò1Ð2EÑFÔFð 'ð 'ˆØ�|Š|‰~Œ~‰ˆˆ1Ø�
Š?ˆ?å”7—=’= Ñ#Ô# AÔ&Ð&Ð&Ð&ð ð ˆ4ó    c                 ó  — |ot           j                             |¦  «        }|r|s|}nct          | j                             dd¦  «        ¦  «        }|st          j        d¦  «        ‚|r!t           j                             ||¦  «        }n|}|S )aõ  
    Given a response and a path, return a file path for a download.

    If a ``path`` parameter is a directory, this function will parse the
    ``Content-Disposition`` header on the response to determine the name of the
    file as reported by the server, and return a file path in the specified
    directory.

    If ``path`` is empty or None, this function will return a path relative
    to the process' current working directory.

    If path is a full file path, return it.

    :param response: A Response object from requests
    :type response: requests.models.Response
    :param str path: Directory or file path.
    :returns: full file path to download as
    :rtype: str
    :raises: :class:`requests_toolbelt.exceptions.StreamingError`
    zcontent-dispositionÚ z'No filename given to stream response to)	r   r   Úisdirr   ÚheadersÚgetÚexcÚStreamingErrorÚjoin)Úresponser   Úpath_is_dirÚfilepathÚresponse_filenames        r   Úget_download_file_pathr!      s¢   € ð* Ð.�2œ7Ÿ=š=¨Ñ.Ô.€Kàð )�Kð )àˆˆå)ØÔ× Ò Ð!6¸Ñ;Ô;ñ
ô 
Ðð !ð 	PÝÔ$Ð%NÑOÔOÐOàð 	)å”w—|’| DÐ*;Ñ<Ô<ˆHˆHð )ˆHà€Or   c                 ó²  — d}d}d}|r4t          t          |dd¦  «        ¦  «        rd}|}t          |dd¦  «        }nVt          | |¦  «        }t          j                             |¦  «        rt          j        d|z  ¦  «        ‚t          |d¦  «        }|  	                    |¬¦  «        D ]}| 
                    |¦  «         Œ|s|                     ¦   «          |S )	a5  Stream a response body to the specified file.

    Either use the ``path`` provided or use the name provided in the
    ``Content-Disposition`` header.

    .. warning::

        If you pass this function an open file-like object as the ``path``
        parameter, the function will not close that file for you.

    .. warning::

        This function will not automatically close the response object
        passed in as the ``response`` parameter.

    If a ``path`` parameter is a directory, this function will parse the
    ``Content-Disposition`` header on the response to determine the name of the
    file as reported by the server, and return a file path in the specified
    directory. If no ``path`` parameter is supplied, this function will default
    to the process' current working directory.

    .. code-block:: python

        import requests
        from requests_toolbelt import exceptions
        from requests_toolbelt.downloadutils import stream

        r = requests.get(url, stream=True)
        try:
            filename = stream.stream_response_to_file(r)
        except exceptions.StreamingError as e:
            # The toolbelt could not find the filename in the
            # Content-Disposition
            print(e.message)

    You can also specify the filename as a string. This will be passed to
    the built-in :func:`open` and we will read the content into the file.

    .. code-block:: python

        import requests
        from requests_toolbelt.downloadutils import stream

        r = requests.get(url, stream=True)
        filename = stream.stream_response_to_file(r, path='myfile')

    If the calculated download file path already exists, this function will
    raise a StreamingError.

    Instead, if you want to manage the file object yourself, you need to
    provide either a :class:`io.BytesIO` object or a file opened with the
    `'b'` flag. See the two examples below for more details.

    .. code-block:: python

        import requests
        from requests_toolbelt.downloadutils import stream

        with open('myfile', 'wb') as fd:
            r = requests.get(url, stream=True)
            filename = stream.stream_response_to_file(r, path=fd)

        print('{} saved to {}'.format(url, filename))

    .. code-block:: python

        import io
        import requests
        from requests_toolbelt.downloadutils import stream

        b = io.BytesIO()
        r = requests.get(url, stream=True)
        filename = stream.stream_response_to_file(r, path=b)
        assert filename is None

    :param response: A Response object from requests
    :type response: requests.models.Response
    :param path: *(optional)*, Either a string with the path to the location
        to save the response content, or a file-like object expecting bytes.
    :type path: :class:`str`, or object with a :meth:`write`
    :param int chunksize: (optional), Size of chunk to attempt to stream
        (default 512B).
    :returns: The name of the file, if one can be determined, else None
    :rtype: str
    :raises: :class:`requests_toolbelt.exceptions.StreamingError`
    FNÚwriteTÚnamezFile already exists: %sÚwb)Ú
chunk_size)ÚcallableÚgetattrr!   r   r   Úexistsr   r   ÚopenÚiter_contentr#   Úclose)r   r   Ú	chunksizeÚ
pre_openedÚfdr   Úchunks          r   Ústream_response_to_filer1   F   së   € ðn €JØ	€BØ€HØð "•�  w°Ñ5Ô5Ñ6Ô6ð "Øˆ
ØˆÝ˜2˜v tÑ,Ô,ˆˆå)¨(°DÑ9Ô9ˆÝŒ7�>Š>˜(Ñ#Ô#ð 	KÝÔ$Ð%>ÀÑ%IÑJÔJÐJÝ�(˜DÑ!Ô!ˆà×&Ò&°)Ð&Ñ<Ô<ð ð ˆØ
�Š�‰Œˆˆàð Ø
�Š‰
Œ
ˆ
à€Or   )Ú__doc__Úos.pathr   Úrer   r   r   Ú_QUOTED_STRING_REÚcompiler   Ú_DEFAULT_CHUNKSIZEr   r!   r1   © r   r   ú<module>r9      s¸   ðà 3Ð 3Ø €€€Ø 	€	€	€	à  Ð  Ð  Ð  Ð  Ð  ð 0Ð Ø$˜"œ*˜*Ø5FÐ5FÐ5FØ5FÐ5FÐ5FðHñô Ð ð Ð ðð ð ð(ð (ð (ðV ,0Ð;Mð jð jð jð jð jð jr   