Skip to content
Myr

simplify

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 8565053 · Browse files · 1 file+0 added−115 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+0 added−115 removed

  • other:+0 added−115 removed

1 file+0 added−115 removed

modified:requests/models.py-115 removed
79 unmodified lines
80 #: :class:`Response <Response>` instance, containing81 #: content and metadata of HTTP Response, once :attr:`sent <send>`.82 self.response = Response()8384 # if isinstance(auth, (list, tuple)):85 # auth = AuthObject(*auth)86 # if not auth:87 # auth = auth_manager.get_auth(self.url)8884 #: :class:`AuthObject` to attach to :class:`Request <Request>`.85 # self.auth = auth8687 #: CookieJar to attach to :class:`Request <Request>`.
26 unmodified lines
114115 if not self.url:116 raise URLRequired117123 def _get_opener(self):124 """Creates appropriate opener object for urllib2."""125126 _handlers = []127128 if self.cookiejar is not None:129 _handlers.append(urllib2.HTTPCookieProcessor(self.cookiejar))130131 if self.auth:132 if not isinstance(self.auth.handler,133 (urllib2.AbstractBasicAuthHandler,134 urllib2.AbstractDigestAuthHandler)):135136 # TODO: REMOVE THIS COMPLETELY137 auth_manager.add_password(138 self.auth.realm, self.url,139 self.auth.username,140 self.auth.password)141142 self.auth.handler = self.auth.handler(auth_manager)143 auth_manager.add_auth(self.url, self.auth)144145 _handlers.append(self.auth.handler)146147 if self.proxies:148 _handlers.append(urllib2.ProxyHandler(self.proxies))149150 _handlers.append(HTTPRedirectHandler)151152 if not _handlers:153 return urllib2.urlopen154155 if self.data or self.files:156 _handlers.extend(get_handlers())157158 opener = urllib2.build_opener(*_handlers)159160 if self.headers:161 # Allow default headers in the opener to be overloaded162 normal_keys = [k.capitalize() for k in self.headers]163 for key, val in opener.addheaders[:]:164 if key not in normal_keys:165 continue166 # Remove it, we have a value to take its place167 opener.addheaders.remove((key, val))168169 return opener.open170118 def _build_response(self, resp, is_error=False):119 """Build internal :class:`Response <Response>` object120 from given response.121 """
5 unmodified lines
127128 try:129 response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))130 response.raw = resp184 # print dir(self.response.raw)185 # print self131187 # print (response.raw)188 # print dir(response.raw)189 # print response.raw.sock.read()190 # print '------'191192193 # if self.cookiejar:194195 # response.cookies = dict_from_cookiejar(self.cookiejar)196197198 # response.cookies = dict_from_cookiejar(self.cookiejar)199200 # response.cookies = dict_from_cookiejar(self.cookiejar)201132 except AttributeError:133 pass134135 if is_error:
248 unmodified lines
384 raise RuntimeError(385 'The content for this response was already consumed')386387 # Read the contents.458 # print self.raw.__dict__459460 # print461 # print '~'462 # # print self.raw463 # print self.raw.getresponse()464 # print dir(self.raw)465 # print466 # print467 # print468469 # self.raw.read() or388 self._content = self.raw.read() or self.raw.data471 # print self.raw.__dict__389390 # Decode GZip'd content.391 if 'gzip' in self.headers.get('content-encoding', ''):392 try:
25 unmodified lines
418 raise Exception('400 yo')419420 elif (self.status_code >= 500) and (self.status_code < 600):421 raise Exception('500 yo')505506507class AuthObject(object):508 """The :class:`AuthObject` is a simple HTTP Authentication token.509510 When given to a Requests function, it enables Basic HTTP Authentication511 for that Request. You can also enable Authorization for domain realms512 with AutoAuth. See AutoAuth for more details.513514 :param username: Username to authenticate with.515 :param password: Password for given username.516 :param realm: (optional) the realm this auth applies to517 :param handler: (optional) basic || digest || proxy_basic || proxy_digest518 """519520 _handlers = {521 # 'basic': HTTPBasicAuthHandler,522 # 'forced_basic': HTTPForcedBasicAuthHandler,523 # 'digest': HTTPDigestAuthHandler,524 # 'proxy_basic': urllib2.ProxyBasicAuthHandler,525 # 'proxy_digest': urllib2.ProxyDigestAuthHandler526 }527528 def __init__(self, username, password, handler='forced_basic', realm=None):529 self.username = username530 self.password = password531 self.realm = realm532533 if isinstance(handler, basestring):534 self.handler = self._handlers.get(handler.lower(), HTTPForcedBasicAuthHandler)535 else:536 self.handler = handler