mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #2153 from jschneier/master
handle urllib3 api changes; closes #2045
This commit is contained in:
@@ -92,7 +92,6 @@ if is_py2:
|
||||
from Cookie import Morsel
|
||||
from StringIO import StringIO
|
||||
from .packages.urllib3.packages.ordered_dict import OrderedDict
|
||||
from httplib import IncompleteRead
|
||||
|
||||
builtin_str = str
|
||||
bytes = str
|
||||
@@ -108,7 +107,6 @@ elif is_py3:
|
||||
from http.cookies import Morsel
|
||||
from io import StringIO
|
||||
from collections import OrderedDict
|
||||
from http.client import IncompleteRead
|
||||
|
||||
builtin_str = str
|
||||
str = str
|
||||
|
||||
+5
-5
@@ -9,7 +9,6 @@ This module contains the primary objects that power Requests.
|
||||
|
||||
import collections
|
||||
import datetime
|
||||
import socket
|
||||
|
||||
from io import BytesIO, UnsupportedOperation
|
||||
from .hooks import default_hooks
|
||||
@@ -20,7 +19,8 @@ from .cookies import cookiejar_from_dict, get_cookie_header
|
||||
from .packages.urllib3.fields import RequestField
|
||||
from .packages.urllib3.filepost import encode_multipart_formdata
|
||||
from .packages.urllib3.util import parse_url
|
||||
from .packages.urllib3.exceptions import DecodeError
|
||||
from .packages.urllib3.exceptions import (
|
||||
DecodeError, ReadTimeoutError, ProtocolError)
|
||||
from .exceptions import (
|
||||
HTTPError, RequestException, MissingSchema, InvalidURL,
|
||||
ChunkedEncodingError, ContentDecodingError, ConnectionError)
|
||||
@@ -30,7 +30,7 @@ from .utils import (
|
||||
iter_slices, guess_json_utf, super_len, to_native_string)
|
||||
from .compat import (
|
||||
cookielib, urlunparse, urlsplit, urlencode, str, bytes, StringIO,
|
||||
is_py2, chardet, json, builtin_str, basestring, IncompleteRead)
|
||||
is_py2, chardet, json, builtin_str, basestring)
|
||||
from .status_codes import codes
|
||||
|
||||
#: The set of HTTP status codes that indicate an automatically
|
||||
@@ -637,11 +637,11 @@ class Response(object):
|
||||
try:
|
||||
for chunk in self.raw.stream(chunk_size, decode_content=True):
|
||||
yield chunk
|
||||
except IncompleteRead as e:
|
||||
except ProtocolError as e:
|
||||
raise ChunkedEncodingError(e)
|
||||
except DecodeError as e:
|
||||
raise ContentDecodingError(e)
|
||||
except socket.error as e:
|
||||
except ReadTimeoutError as e:
|
||||
raise ConnectionError(e)
|
||||
except AttributeError:
|
||||
# Standard file-like object.
|
||||
|
||||
@@ -720,18 +720,6 @@ class RequestsTestCase(unittest.TestCase):
|
||||
assert next(iter(r))
|
||||
io.close()
|
||||
|
||||
def test_iter_content_handles_socket_error(self):
|
||||
r = requests.Response()
|
||||
import socket
|
||||
|
||||
class RawMock(object):
|
||||
def stream(self, chunk_size, decode_content=None):
|
||||
raise socket.error()
|
||||
|
||||
r.raw = RawMock()
|
||||
with pytest.raises(ConnectionError):
|
||||
list(r.iter_content())
|
||||
|
||||
def test_response_decode_unicode(self):
|
||||
"""
|
||||
When called with decode_unicode, Response.iter_content should always
|
||||
|
||||
Reference in New Issue
Block a user