Wrap IncompleteRead in ChunkedEncodingError.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Cory Benfield · committed by Cory Benfield · parent 9473f15 · Browse files · 3 files·+16 added−4 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+16 added−4 removed
- other:+16 added−4 removed
Provenance
- Commit
79f3e69- Tree
ce787b5- Author
Cory Benfield <lukasaoz@gmail.com>- Committer
Cory Benfield <lukasaoz@gmail.com>- Parent
9473f15
3 files changed+16 added−4 removed
modified:requests/compat.py+2 added
88 unmodified lines89 import cookielib90 from Cookie import Morsel91 from StringIO import StringIO92 from .packages.urllib3.packages.ordered_dict import OrderedDict93+ from httplib import IncompleteRead94 95 builtin_str = str96 bytes = str97 str = unicode7 unmodified lines105 from http import cookiejar as cookielib106 from http.cookies import Morsel107 from io import StringIO108 from collections import OrderedDict109+ from http.client import IncompleteRead110 111 builtin_str = str112 str = str113 bytes = bytes2 unmodified linesmodified:requests/exceptions.py+4 added
51 unmodified lines52 53 54 class InvalidURL(RequestException, ValueError):55 """ The URL provided was somehow invalid. """56+57+58+class ChunkedEncodingError(RequestException):59+ """The server declared chunked encoding but sent an invalid chunk."""modified:requests/models.py+10 added-4 removed
17 unmodified lines18 from .auth import HTTPBasicAuth19 from .cookies import cookiejar_from_dict, get_cookie_header20 from .packages.urllib3.filepost import encode_multipart_formdata21 from .packages.urllib3.util import parse_url22-from .exceptions import HTTPError, RequestException, MissingSchema, InvalidURL22+from .exceptions import (23+ HTTPError, RequestException, MissingSchema, InvalidURL,24+ ChunkedEncodingError)25 from .utils import (26 guess_filename, get_auth_from_url, requote_uri,27 stream_decode_response_unicode, to_key_val_list, parse_header_links,28 iter_slices, guess_json_utf, super_len)29 from .compat import (30 cookielib, urlunparse, urlsplit, urlencode, str, bytes, StringIO,29- is_py2, chardet, json, builtin_str, basestring)31+ is_py2, chardet, json, builtin_str, basestring, IncompleteRead)32 33 CONTENT_CHUNK_SIZE = 10 * 102434 ITER_CHUNK_SIZE = 51235 512 unmodified lines548 549 def generate():550 try:551 # Special case for urllib3.552+ try:553+ for chunk in self.raw.stream(chunk_size,550- for chunk in self.raw.stream(chunk_size, decode_content=True):551- yield chunk554+ decode_content=True):555+ yield chunk556+ except IncompleteRead as e:557+ raise ChunkedEncodingError(e)558 except AttributeError:559 # Standard file-like object.560 while 1:561 chunk = self.raw.read(chunk_size)151 unmodified lines