parameters: (self, amt=None, decode_content=None, cache_content=False)
docstring: Similar to :meth:`httplib.HTTPResponse.read`, but with two additional
          parameters: ``decode_content`` and ``cache_content``.
  
          :param amt:
              How much of the content to read. If specified, caching is skipped
              because it doesn't make sense to cache partial content as the full
              response.
  
          :param decode_content:
              If True, will attempt to decode the body based on the
              'content-encoding' header.
  
          :param cache_content:
              If True, will save the returned data such that the same result is
              returned despite of the state of the underlying file object. This
              is useful if you want the ``.data`` property to continue working
              after having ``.read()`` the file object. (Overridden if ``amt`` is
              set.)
docstring_summary: Similar to :meth:`httplib.HTTPResponse.read`, but with two additional
          parameters: ``decode_content`` and ``cache_content``.
docstring_tokens: Similar to : meth : httplib . HTTPResponse . read but with two additional parameters : decode_content and cache_content .
function: def read(self, amt=None, decode_content=None, cache_content=False):
          """
          Similar to :meth:`httplib.HTTPResponse.read`, but with two additional
          parameters: ``decode_content`` and ``cache_content``.
  
          :param amt:
              How much of the content to read. If specified, caching is skipped
              because it doesn't make sense to cache partial content as the full
              response.
  
          :param decode_content:
              If True, will attempt to decode the body based on the
              'content-encoding' header.
  
          :param cache_content:
              If True, will save the returned data such that the same result is
              returned despite of the state of the underlying file object. This
              is useful if you want the ``.data`` property to continue working
              after having ``.read()`` the file object. (Overridden if ``amt`` is
              set.)
          """
          # Note: content-encoding value should be case-insensitive, per RFC 7230
          # Section 3.2
          content_encoding = self.headers.get('content-encoding', '').lower()
          if self._decoder is None:
              if content_encoding in self.CONTENT_DECODERS:
                  self._decoder = _get_decoder(content_encoding)
          if decode_content is None:
              decode_content = self.decode_content
  
          if self._fp is None:
              return
  
          flush_decoder = False
  
          try:
              try:
                  if amt is None:
                      # cStringIO doesn't like amt=None
                      data = self._fp.read()
                      flush_decoder = True
                  else:
                      cache_content = False
                      data = self._fp.read(amt)
                      if amt != 0 and not data:  # Platform-specific: Buggy versions of Python.
                          # Close the connection when no data is returned
                          #
                          # This is redundant to what httplib/http.client _should_
                          # already do.  However, versions of python released before
                          # December 15, 2012 (http://bugs.python.org/issue16298) do
                          # not properly close the connection in all cases. There is
                          # no harm in redundantly calling close.
                          self._fp.close()
                          flush_decoder = True
  
              except SocketTimeout:
                  # FIXME: Ideally we'd like to include the url in the ReadTimeoutError but
                  # there is yet no clean way to get at it from this context.
                  raise ReadTimeoutError(self._pool, None, 'Read timed out.')
  
              except BaseSSLError as e:
                  # FIXME: Is there a better way to differentiate between SSLErrors?
                  if not 'read operation timed out' in str(e):  # Defensive:
                      # This shouldn't happen but just in case we're missing an edge
                      # case, let's avoid swallowing SSL errors.
                      raise
  
                  raise ReadTimeoutError(self._pool, None, 'Read timed out.')
  
              except HTTPException as e:
                  # This includes IncompleteRead.
                  raise ProtocolError('Connection broken: %r' % e, e)
  
              self._fp_bytes_read += len(data)
  
              try:
                  if decode_content and self._decoder:
                      data = self._decoder.decompress(data)
              except (IOError, zlib.error) as e:
                  raise DecodeError(
                      "Received response with content-encoding: %s, but "
                      "failed to decode it." % content_encoding, e)
  
              if flush_decoder and decode_content and self._decoder:
                  buf = self._decoder.decompress(binary_type())
                  data += buf + self._decoder.flush()
  
              if cache_content:
                  self._body = data
  
              return data
  
          finally:
              if self._original_response and self._original_response.isclosed():
                  self.release_conn()
function_tokens: def read ( self , amt = None , decode_content = None , cache_content = False ) : # Note: content-encoding value should be case-insensitive, per RFC 7230 # Section 3.2 content_encoding = self . headers . get ( 'content-encoding' , '' ) . lower ( ) if self . _decoder is None : if content_encoding in self . CONTENT_DECODERS : self . _decoder = _get_decoder ( content_encoding ) if decode_content is None : decode_content = self . decode_content if self . _fp is None : return flush_decoder = False try : try : if amt is None : # cStringIO doesn't like amt=None data = self . _fp . read ( ) flush_decoder = True else : cache_content = False data = self . _fp . read ( amt ) if amt != 0 and not data : # Platform-specific: Buggy versions of Python. # Close the connection when no data is returned # # This is redundant to what httplib/http.client _should_ # already do.  However, versions of python released before # December 15, 2012 (http://bugs.python.org/issue16298) do # not properly close the connection in all cases. There is # no harm in redundantly calling close. self . _fp . close ( ) flush_decoder = True except SocketTimeout : # FIXME: Ideally we'd like to include the url in the ReadTimeoutError but # there is yet no clean way to get at it from this context. raise ReadTimeoutError ( self . _pool , None , 'Read timed out.' ) except BaseSSLError as e : # FIXME: Is there a better way to differentiate between SSLErrors? if not 'read operation timed out' in str ( e ) : # Defensive: # This shouldn't happen but just in case we're missing an edge # case, let's avoid swallowing SSL errors. raise raise ReadTimeoutError ( self . _pool , None , 'Read timed out.' ) except HTTPException as e : # This includes IncompleteRead. raise ProtocolError ( 'Connection broken: %r' % e , e ) self . _fp_bytes_read += len ( data ) try : if decode_content and self . _decoder : data = self . _decoder . decompress ( data ) except ( IOError , zlib . error ) as e : raise DecodeError ( "Received response with content-encoding: %s, but " "failed to decode it." % content_encoding , e ) if flush_decoder and decode_content and self . _decoder : buf = self . _decoder . decompress ( binary_type ( ) ) data += buf + self . _decoder . flush ( ) if cache_content : self . _body = data return data finally : if self . _original_response and self . _original_response . isclosed ( ) : self . release_conn ( )