(self, amt=None, decode_content=None)
Similar to :meth:`HTTPResponse.read`, but with an additional
        parameter: ``decode_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.
Similar to :meth:`HTTPResponse.read`, but with an additional
        parameter: ``decode_content``.
Similar to : meth : HTTPResponse . read but with an additional parameter : decode_content .
def read_chunked(self, amt=None, decode_content=None):
        """
        Similar to :meth:`HTTPResponse.read`, but with an additional
        parameter: ``decode_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.
        """
        self._init_decoder()
        # FIXME: Rewrite this method and make it a class with a better structured logic.
        if not self.chunked:
            raise ResponseNotChunked(
                "Response is not chunked. "
                "Header 'transfer-encoding: chunked' is missing.")
        if not self.supports_chunked_reads():
            raise BodyNotHttplibCompatible(
                "Body should be httplib.HTTPResponse like. "
                "It should have have an fp attribute which returns raw chunks.")

        with self._error_catcher():
            # Don't bother reading the body of a HEAD request.
            if self._original_response and is_response_to_head(self._original_response):
                self._original_response.close()
                return

            # If a response is already read and closed
            # then return immediately.
            if self._fp.fp is None:
                return

            while True:
                self._update_chunk_length()
                if self.chunk_left == 0:
                    break
                chunk = self._handle_chunk(amt)
                decoded = self._decode(chunk, decode_content=decode_content,
                                       flush_decoder=False)
                if decoded:
                    yield decoded

            if decode_content:
                # On CPython and PyPy, we should never need to flush the
                # decoder. However, on Jython we *might* need to, so
                # lets defensively do it anyway.
                decoded = self._flush_decoder()
                if decoded:  # Platform-specific: Jython.
                    yield decoded

            # Chunk content ends with \r\n: discard it.
            while True:
                line = self._fp.fp.readline()
                if not line:
                    # Some sites may not end with '\r\n'.
                    break
                if line == b'\r\n':
                    break

            # We read everything; close the "file".
            if self._original_response:
                self._original_response.close()
def read_chunked ( self , amt = None , decode_content = None ) : self . _init_decoder ( ) # FIXME: Rewrite this method and make it a class with a better structured logic. if not self . chunked : raise ResponseNotChunked ( "Response is not chunked. " "Header 'transfer-encoding: chunked' is missing." ) if not self . supports_chunked_reads ( ) : raise BodyNotHttplibCompatible ( "Body should be httplib.HTTPResponse like. " "It should have have an fp attribute which returns raw chunks." ) with self . _error_catcher ( ) : # Don't bother reading the body of a HEAD request. if self . _original_response and is_response_to_head ( self . _original_response ) : self . _original_response . close ( ) return # If a response is already read and closed # then return immediately. if self . _fp . fp is None : return while True : self . _update_chunk_length ( ) if self . chunk_left == 0 : break chunk = self . _handle_chunk ( amt ) decoded = self . _decode ( chunk , decode_content = decode_content , flush_decoder = False ) if decoded : yield decoded if decode_content : # On CPython and PyPy, we should never need to flush the # decoder. However, on Jython we *might* need to, so # lets defensively do it anyway. decoded = self . _flush_decoder ( ) if decoded : # Platform-specific: Jython. yield decoded # Chunk content ends with \r\n: discard it. while True : line = self . _fp . fp . readline ( ) if not line : # Some sites may not end with '\r\n'. break if line == b'\r\n' : break # We read everything; close the "file". if self . _original_response : self . _original_response . close ( )