Merge pull request #2153 from jschneier/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
handle urllib3 api changes; closes #2045
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 3eb69be, 47d0517 · Browse files · 3 files·+5 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+5 added−19 removed
- other:+5 added−19 removed
Provenance
- Commit
35d083e- Tree
3691fe4- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent 1
3eb69be- Parent 2
47d0517
3 files changed+5 added−19 removed
modified:requests/compat.py-2 removed
90 unmodified lines91 import cookielib92 from Cookie import Morsel93 from StringIO import StringIO94 from .packages.urllib3.packages.ordered_dict import OrderedDict95- from httplib import IncompleteRead95 96 builtin_str = str97 bytes = str98 str = unicode7 unmodified lines106 from http import cookiejar as cookielib107 from http.cookies import Morsel108 from io import StringIO109 from collections import OrderedDict111- from http.client import IncompleteRead110 111 builtin_str = str112 str = str113 bytes = bytes2 unmodified linesmodified:requests/models.py+5 added-5 removed
7 unmodified lines8 """9 10 import collections11 import datetime12-import socket12 13 from io import BytesIO, UnsupportedOperation14 from .hooks import default_hooks15 from .structures import CaseInsensitiveDict2 unmodified lines18 from .cookies import cookiejar_from_dict, get_cookie_header19 from .packages.urllib3.fields import RequestField20 from .packages.urllib3.filepost import encode_multipart_formdata21 from .packages.urllib3.util import parse_url23-from .packages.urllib3.exceptions import DecodeError22+from .packages.urllib3.exceptions import (23+ DecodeError, ReadTimeoutError, ProtocolError)24 from .exceptions import (25 HTTPError, RequestException, MissingSchema, InvalidURL,26 ChunkedEncodingError, ContentDecodingError, ConnectionError)27 from .utils import (1 unmodified line29 stream_decode_response_unicode, to_key_val_list, parse_header_links,30 iter_slices, guess_json_utf, super_len, to_native_string)31 from .compat import (32 cookielib, urlunparse, urlsplit, urlencode, str, bytes, StringIO,33- is_py2, chardet, json, builtin_str, basestring, IncompleteRead)33+ is_py2, chardet, json, builtin_str, basestring)34 from .status_codes import codes35 36 #: The set of HTTP status codes that indicate an automatically37 #: processable redirect.598 unmodified lines636 # Special case for urllib3.637 try:638 for chunk in self.raw.stream(chunk_size, decode_content=True):639 yield chunk640- except IncompleteRead as e:640+ except ProtocolError as e:641 raise ChunkedEncodingError(e)642 except DecodeError as e:643 raise ContentDecodingError(e)644- except socket.error as e:644+ except ReadTimeoutError as e:645 raise ConnectionError(e)646 except AttributeError:647 # Standard file-like object.648 while True:168 unmodified linesmodified:test_requests.py-12 removed
718 unmodified lines719 r.raw = io720 assert next(iter(r))721 io.close()722 723- def test_iter_content_handles_socket_error(self):724- r = requests.Response()725- import socket726-727- class RawMock(object):728- def stream(self, chunk_size, decode_content=None):729- raise socket.error()730-731- r.raw = RawMock()732- with pytest.raises(ConnectionError):733- list(r.iter_content())734-723 def test_response_decode_unicode(self):724 """725 When called with decode_unicode, Response.iter_content should always726 return unicode.699 unmodified lines