File: //lib/python2.7/site-packages/requests_toolbelt/downloadutils/tee.pyc
ó
Óµ Yc @ sa d Z d d l Z d Z d d d g Z d „ Z e d d „ Z e d d „ Z e d d
„ Z d S( s Tee function implementations.iÿÿÿÿNi t teet tee_to_filet tee_to_bytearrayc c s9 x2 | j j d | d | ƒ D] } | | ƒ | Vq Wd S( Nt amtt decode_content( t rawt stream( t responset callbackt chunksizeR t chunk( ( sG /usr/lib/python2.7/site-packages/requests_toolbelt/downloadutils/tee.pyt _tee s
c C sO d t | d d ƒ k p' t | t j ƒ s9 t d ƒ ‚ n t | | j | | ƒ S( s" 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.
t bt modet sƒ tee() 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.( t getattrt
isinstancet iot BytesIOt TypeErrorR t write( R t
fileobjectR R ( ( sG /usr/lib/python2.7/site-packages/requests_toolbelt/downloadutils/tee.pyR s (c c sA t | d ƒ , } x"