Skip to content
Myr

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

1 file+26 added−19 removed

modified:requests/models.py+26 added-19 removed
19 unmodified lines
20from .packages import urllib321# print dir(urllib3)2223from .config import settings24from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler24from .structures import CaseInsensitiveDict26# from .packages.poster.encode import multipart_encode27# from .packages.poster.streaminghttp import register_openers, get_handlers25from .utils import dict_from_cookiejar, get_unicode_from_response, stream_decode_response_unicode, decode_gzip, stream_decode_gzip26from .status_codes import codes30from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, TooManyRedirects27from .exceptions import RequestException, Timeout, URLRequired, TooManyRedirects282930REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)31
173 unmodified lines
205 history = []206207208 r = build(resp)209 r._response = resp210211 if r.status_code in REDIRECT_STATI and not self.redirect:212213 while (
86 unmodified lines
300 else:301 return self.url302303306 def send(self, anyway=False):304 def send(self, connection=None, anyway=False):305 """Sends the shit."""306307 # Safety check.308 self._checks()
8 unmodified lines
317 # redirect=True, assert_same_host=True):318 # req = _Request(url, data=self._enc_data, method=self.method)319320323 if not self.sent or anyway:321 if (anyway) or (not self.sent):322323 try:324 if not connection:325 connection = urllib3.connection_from_url(url,326 timeout=self.timeout)327 do_block = False328 else:329 do_block = True330327 pool = urllib3.connection_from_url(url, timeout=self.timeout)328329 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 )340341 # r.socket = pool._get_conn().sock342 # r.fo = r.data
182 unmodified lines
525 if decode_unicode:526 gen = stream_decode_response_unicode(gen, self)527 return gen528529530 @property531 def content(self):532 """Content of the response, in bytes or unicode533 (if available).
2 unmodified lines
536 if self._content is not None:537 return self._content538539 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')542543 # 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__547548 # Decode GZip'd content.549 if 'gzip' in self.headers.get('content-encoding', ''):550 try:
9 unmodified lines
560 return self._content561562563 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 """567568 if self.error:569 raise self.error570
164 unmodified lines
735 :param handler: (optional) basic || digest || proxy_basic || proxy_digest736 """737738 _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 }745746 def __init__(self, username, password, handler='forced_basic', realm=None):747 self.username = username
7 unmodified lines