~ubuntu-branches/ubuntu/wily/python-urllib3/wily

« back to all changes in this revision

Viewing changes to .pc/01_do-not-use-embedded-python-six.patch/urllib3/response.py

  • Committer: Package Import Robot
  • Author(s): Daniele Tricoli
  • Date: 2014-07-07 16:09:06 UTC
  • mfrom: (4.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140707160906-hv2d4zrlg8u7rjby
Tags: 1.8.3-1
* New upstream release (Closes: #754090)
* debian/patches/01_do-not-use-embedded-python-six.patch
  - Refresh
* debian/patches/04_relax_nosetests_options.patch
  - Refresh

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
# the MIT License: http://www.opensource.org/licenses/mit-license.php
6
6
 
7
7
 
8
 
import logging
9
8
import zlib
10
9
import io
 
10
from socket import timeout as SocketTimeout
11
11
 
12
12
from ._collections import HTTPHeaderDict
13
 
from .exceptions import DecodeError
 
13
from .exceptions import DecodeError, ReadTimeoutError
14
14
from .packages.six import string_types as basestring, binary_type
15
15
from .util import is_fp_closed
16
16
 
17
17
 
18
 
log = logging.getLogger(__name__)
19
 
 
20
 
 
21
18
class DeflateDecoder(object):
22
19
 
23
20
    def __init__(self):
163
160
            after having ``.read()`` the file object. (Overridden if ``amt`` is
164
161
            set.)
165
162
        """
166
 
        # Note: content-encoding value should be case-insensitive, per RFC 2616
167
 
        # Section 3.5
 
163
        # Note: content-encoding value should be case-insensitive, per RFC 7230
 
164
        # Section 3.2
168
165
        content_encoding = self.headers.get('content-encoding', '').lower()
169
166
        if self._decoder is None:
170
167
            if content_encoding in self.CONTENT_DECODERS:
178
175
        flush_decoder = False
179
176
 
180
177
        try:
181
 
            if amt is None:
182
 
                # cStringIO doesn't like amt=None
183
 
                data = self._fp.read()
184
 
                flush_decoder = True
185
 
            else:
186
 
                cache_content = False
187
 
                data = self._fp.read(amt)
188
 
                if amt != 0 and not data:  # Platform-specific: Buggy versions of Python.
189
 
                    # Close the connection when no data is returned
190
 
                    #
191
 
                    # This is redundant to what httplib/http.client _should_
192
 
                    # already do.  However, versions of python released before
193
 
                    # December 15, 2012 (http://bugs.python.org/issue16298) do not
194
 
                    # properly close the connection in all cases. There is no harm
195
 
                    # in redundantly calling close.
196
 
                    self._fp.close()
 
178
            try:
 
179
                if amt is None:
 
180
                    # cStringIO doesn't like amt=None
 
181
                    data = self._fp.read()
197
182
                    flush_decoder = True
 
183
                else:
 
184
                    cache_content = False
 
185
                    data = self._fp.read(amt)
 
186
                    if amt != 0 and not data:  # Platform-specific: Buggy versions of Python.
 
187
                        # Close the connection when no data is returned
 
188
                        #
 
189
                        # This is redundant to what httplib/http.client _should_
 
190
                        # already do.  However, versions of python released before
 
191
                        # December 15, 2012 (http://bugs.python.org/issue16298) do
 
192
                        # not properly close the connection in all cases. There is
 
193
                        # no harm in redundantly calling close.
 
194
                        self._fp.close()
 
195
                        flush_decoder = True
 
196
 
 
197
            except SocketTimeout:
 
198
                # FIXME: Ideally we'd like to include the url in the ReadTimeoutError but
 
199
                # there is yet no clean way to get at it from this context.
 
200
                raise ReadTimeoutError(self._pool, None, 'Read timed out.')
198
201
 
199
202
            self._fp_bytes_read += len(data)
200
203
 
204
207
            except (IOError, zlib.error) as e:
205
208
                raise DecodeError(
206
209
                    "Received response with content-encoding: %s, but "
207
 
                    "failed to decode it." % content_encoding,
208
 
                    e)
 
210
                    "failed to decode it." % content_encoding, e)
209
211
 
210
212
            if flush_decoder and decode_content and self._decoder:
211
213
                buf = self._decoder.decompress(binary_type())
242
244
            if data:
243
245
                yield data
244
246
 
245
 
 
246
247
    @classmethod
247
248
    def from_httplib(ResponseCls, r, **response_kw):
248
249
        """
297
298
        elif hasattr(self._fp, "fileno"):
298
299
            return self._fp.fileno()
299
300
        else:
300
 
            raise IOError("The file-like object  this HTTPResponse is wrapped "
 
301
            raise IOError("The file-like object this HTTPResponse is wrapped "
301
302
                          "around has no file descriptor")
302
303
 
303
304
    def flush(self):