
    8i                     L    S r SSKrSr/ SQrS r\S4S jr\S4S jr\S4S jrg)	zTee function implementations.    Ni   )teetee_to_filetee_to_bytearrayc              #   f   #    U R                   R                  UUS9 H  nU" U5        Uv   M     g 7f)N)amtdecode_content)rawstream)responsecallback	chunksizer   chunks        s/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/requests_toolbelt/downloadutils/tee.py_teer   	   s6     $$4B % DDs   /1c                     S[        USS5      ;   d*  [        U[        R                  5      (       d  [	        S5      e[        XR                  X#5      $ )a  Stream the response both to the generator and a file.

This will stream the response body while writing the bytes to
``fileobject``.

Example usage:

.. code-block:: python

    resp = requests.get(url, stream=True)
    with open('save_file', 'wb') as save_file:
        for chunk in tee(resp, save_file):
            # do stuff with chunk

.. code-block:: python

    import io

    resp = requests.get(url, stream=True)
    fileobject = io.BytesIO()

    for chunk in tee(resp, fileobject):
        # do stuff with chunk

:param response: Response from requests.
:type response: requests.Response
:param fileobject: Writable file-like object.
:type fileobject: file, io.BytesIO
:param int chunksize: (optional), Size of chunk to attempt to stream.
:param bool decode_content: (optional), If True, this will decode the
    compressed content of the response.
:raises: TypeError if the fileobject wasn't opened with the right mode
    or isn't a BytesIO object.
bmode ztee() will write bytes directly to this fileobject, it must be opened with the "b" flag if it is a file or inherit from io.BytesIO.)getattr
isinstanceioBytesIO	TypeErrorr   write)r   
fileobjectr   r   s       r   r   r      sN    P 7:vr22z2::.. 7 8 	8 **IFF    c              #      #    [        US5       n[        XX#5       H  nUv   M	     SSS5        g! , (       d  f       g= f7f)a  Stream the response both to the generator and a file.

This will open a file named ``filename`` and stream the response body
while writing the bytes to the opened file object.

Example usage:

.. code-block:: python

    resp = requests.get(url, stream=True)
    for chunk in tee_to_file(resp, 'save_file'):
        # do stuff with chunk

:param response: Response from requests.
:type response: requests.Response
:param str filename: Name of file in which we write the response content.
:param int chunksize: (optional), Size of chunk to attempt to stream.
:param bool decode_content: (optional), If True, this will decode the
    compressed content of the response.
wbN)openr   )r   filenamer   r   fdr   s         r   r   r   A   s5     , 
h	yAEK B 
		s   A0	A
>Ac                 n    [        U[        5      (       d  [        S5      e[        XR                  X#5      $ )a0  Stream the response both to the generator and a bytearray.

This will stream the response provided to the function, add them to the
provided :class:`bytearray` and yield them to the user.

.. note::

    This uses the :meth:`bytearray.extend` by default instead of passing
    the bytearray into the ``readinto`` method.

Example usage:

.. code-block:: python

    b = bytearray()
    resp = requests.get(url, stream=True)
    for chunk in tee_to_bytearray(resp, b):
        # do stuff with chunk

:param response: Response from requests.
:type response: requests.Response
:param bytearray bytearr: Array to add the streamed bytes to.
:param int chunksize: (optional), Size of chunk to attempt to stream.
:param bool decode_content: (optional), If True, this will decode the
    compressed content of the response.
z4tee_to_bytearray() expects bytearr to be a bytearray)r   	bytearrayr   r   extend)r   bytearrr   r   s       r   r   r   \   s4    8 gy)) $ % 	%..)DDr   )__doc__r   _DEFAULT_CHUNKSIZE__all__r   r   r   r    r   r   <module>r*      sG    # 	 
4 );.Gb /A#6 3E$(Er   