Response.fo => Reponse.raw
Before adoption: this commit came in with the history the project adopted, so no landing records it.
raise_for_status() fixes
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 71d3490 · Browse files · 1 file·+20 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+20 added−13 removed
- other:+20 added−13 removed
Provenance
- Commit
a3cc971- Tree
10c37d2- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
71d3490
1 file changed+20 added−13 removed
modified:requests/models.py+20 added-13 removed
16 unmodified lines17 from datetime import datetime18 19 20 from .packages import urllib321-print dir(urllib3)21+# print dir(urllib3)22 23 from .config import settings24 from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler25 from .structures import CaseInsensitiveDict163 unmodified lines189 response.status_code = getattr(resp, 'status', None)190 191 try:192 response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))193- # response.fo = resp193+ response.raw = resp._raw194 195 # if self.cookiejar:196 197 # response.cookies = dict_from_cookiejar(self.cookiejar)3 unmodified lines201 202 if is_error:203 response.error = resp204 205- response.url = getattr(resp, 'url', None)206-205 return response206 207 208 history = []209 210+211 r = build(resp)212 213 if r.status_code in REDIRECT_STATI and not self.redirect:214 2 unmodified lines217 ((r.status_code is codes.see_other) or218 (self.allow_redirects))219 ):220 222- # r.fo.close()221+ r.raw.close()222 223 if not len(history) < settings.max_redirects:224 raise TooManyRedirects()225 105 unmodified lines331 url=url,332 body=self.data,333 headers=self.headers,334 redirect=False,336- assert_same_host=False335+ assert_same_host=False,336+ block=True337 )338 339- r.socket = pool._get_conn().sock339+ # r.socket = pool._get_conn().sock340+ # r.fo = r.data341 342 # if self.cookiejar is not None:343 # self.cookiejar.extract_cookies(resp, req)344 123 unmodified lines468 #: value of a ``'Content-Encoding'`` response header.469 self.headers = CaseInsensitiveDict()470 471 #: File-like object representation of response (for advanced usage).471- self.fo = None472+ self.raw = None473 473- #: Final URL location of Response.474- self.url = None475-474 #: True if no :attr:`error` occured.475 self.ok = False476 477 #: Resulting :class:`HTTPError` of request, if one occured.31 unmodified lines509 'already consumed')510 511 def generate():512 while 1:515- chunk = self.fo.read(chunk_size)513+ chunk = self.raw.read(chunk_size)514 if not chunk:515 break516 yield chunk517 self._content_consumed = True19 unmodified lines537 raise RuntimeError('The content for this response was '538 'already consumed')539 540 # Read the contents.543- self._content = self.fo.read()541+ self._content = self.raw.read()542 543 # Decode GZip'd content.544 if 'gzip' in self.headers.get('content-encoding', ''):545 try:10 unmodified lines556 557 558 def raise_for_status(self):559 """Raises stored :class:`HTTPError` or :class:`URLError`, if one occured."""560+561 if self.error:562 raise self.error563 564+ if (self.status_code >= 300) and (self.status_code < 400):565+ raise Exception('300 yo')566 567+ elif (self.status_code >= 400) and (self.status_code < 500):568+ raise Exception('400 yo')569 570+ elif (self.status_code >= 500) and (self.status_code < 600):571+ raise Exception('500 yo')572+573+574 class AuthManager(object):575 """Requests Authentication Manager."""576 577 def __new__(cls):170 unmodified lines