Gotta catch 'em all!
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 2a2e7bd · Browse files · 1 file·+26 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
1 file+26 added−19 removed
- other:+26 added−19 removed
Provenance
- Commit
645933a- Tree
bf48ff8- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
2a2e7bd
1 file changed+26 added−19 removed
modified:requests/models.py+26 added-19 removed
19 unmodified lines20 from .packages import urllib321 # print dir(urllib3)22 23 from .config import settings24-from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler24 from .structures import CaseInsensitiveDict26-# from .packages.poster.encode import multipart_encode27-# from .packages.poster.streaminghttp import register_openers, get_handlers25 from .utils import dict_from_cookiejar, get_unicode_from_response, stream_decode_response_unicode, decode_gzip, stream_decode_gzip26 from .status_codes import codes30-from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, TooManyRedirects27+from .exceptions import RequestException, Timeout, URLRequired, TooManyRedirects28 29 30 REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)31 173 unmodified lines205 history = []206 207 208 r = build(resp)209+ r._response = resp210 211 if r.status_code in REDIRECT_STATI and not self.redirect:212 213 while (86 unmodified lines300 else:301 return self.url302 303 306- def send(self, anyway=False):304+ def send(self, connection=None, anyway=False):305 """Sends the shit."""306 307 # Safety check.308 self._checks()8 unmodified lines317 # redirect=True, assert_same_host=True):318 # req = _Request(url, data=self._enc_data, method=self.method)319 320 323- if not self.sent or anyway:321+ if (anyway) or (not self.sent):322 323 try:324+ if not connection:325+ connection = urllib3.connection_from_url(url,326+ timeout=self.timeout)327+ do_block = False328+ else:329+ do_block = True330 327- pool = urllib3.connection_from_url(url, timeout=self.timeout)328-329- r = pool.urlopen(331+ r = connection.urlopen(332 method=self.method,333 url=url,334 body=self.data,335 headers=self.headers,336 redirect=False,337 assert_same_host=False,336- block=True338+ block=do_block339 )340 341 # r.socket = pool._get_conn().sock342 # r.fo = r.data182 unmodified lines525 if decode_unicode:526 gen = stream_decode_response_unicode(gen, self)527 return gen528 529+530 @property531 def content(self):532 """Content of the response, in bytes or unicode533 (if available).2 unmodified lines536 if self._content is not None:537 return self._content538 539 if self._content_consumed:537- raise RuntimeError('The content for this response was '538- 'already consumed')540+ raise RuntimeError(541+ 'The content for this response was already consumed')542 543 # Read the contents.544+ # print self.raw.__dict__541- self._content = self.raw.read()545+ self._content = self.raw.read() or self._response.data546+ # print self.raw.__dict__547 548 # Decode GZip'd content.549 if 'gzip' in self.headers.get('content-encoding', ''):550 try:9 unmodified lines560 return self._content561 562 563 def raise_for_status(self):559- """Raises stored :class:`HTTPError` or :class:`URLError`, if one occured."""564+ """Raises stored :class:`HTTPError` or :class:`URLError`,565+ if one occured.566+ """567 568 if self.error:569 raise self.error570 164 unmodified lines735 :param handler: (optional) basic || digest || proxy_basic || proxy_digest736 """737 738 _handlers = {732- 'basic': HTTPBasicAuthHandler,733- 'forced_basic': HTTPForcedBasicAuthHandler,734- 'digest': HTTPDigestAuthHandler,735- 'proxy_basic': urllib2.ProxyBasicAuthHandler,736- 'proxy_digest': urllib2.ProxyDigestAuthHandler739+ # 'basic': HTTPBasicAuthHandler,740+ # 'forced_basic': HTTPForcedBasicAuthHandler,741+ # 'digest': HTTPDigestAuthHandler,742+ # 'proxy_basic': urllib2.ProxyBasicAuthHandler,743+ # 'proxy_digest': urllib2.ProxyDigestAuthHandler744 }745 746 def __init__(self, username, password, handler='forced_basic', realm=None):747 self.username = username7 unmodified lines