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
Provenance
- Commit
bd2b0c4- Tree
9a1d829- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
8565053
1 file changed+0 added−115 removed
modified:requests/models.py-115 removed
79 unmodified lines80 #: :class:`Response <Response>` instance, containing81 #: content and metadata of HTTP Response, once :attr:`sent <send>`.82 self.response = Response()83 84- # if isinstance(auth, (list, tuple)):85- # auth = AuthObject(*auth)86- # if not auth:87- # auth = auth_manager.get_auth(self.url)88-84 #: :class:`AuthObject` to attach to :class:`Request <Request>`.85 # self.auth = auth86 87 #: CookieJar to attach to :class:`Request <Request>`.26 unmodified lines114 115 if not self.url:116 raise URLRequired117 123- def _get_opener(self):124- """Creates appropriate opener object for urllib2."""125-126- _handlers = []127-128- if self.cookiejar is not None:129- _handlers.append(urllib2.HTTPCookieProcessor(self.cookiejar))130-131- if self.auth:132- if not isinstance(self.auth.handler,133- (urllib2.AbstractBasicAuthHandler,134- urllib2.AbstractDigestAuthHandler)):135-136- # TODO: REMOVE THIS COMPLETELY137- auth_manager.add_password(138- self.auth.realm, self.url,139- self.auth.username,140- self.auth.password)141-142- self.auth.handler = self.auth.handler(auth_manager)143- auth_manager.add_auth(self.url, self.auth)144-145- _handlers.append(self.auth.handler)146-147- if self.proxies:148- _handlers.append(urllib2.ProxyHandler(self.proxies))149-150- _handlers.append(HTTPRedirectHandler)151-152- if not _handlers:153- return urllib2.urlopen154-155- if self.data or self.files:156- _handlers.extend(get_handlers())157-158- opener = urllib2.build_opener(*_handlers)159-160- 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))168-169- return opener.open170-118 def _build_response(self, resp, is_error=False):119 """Build internal :class:`Response <Response>` object120 from given response.121 """5 unmodified lines127 128 try:129 response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))130 response.raw = resp184- # print dir(self.response.raw)185- # print self131 187- # print (response.raw)188- # print dir(response.raw)189- # print response.raw.sock.read()190- # print '------'191-192-193- # if self.cookiejar:194-195- # response.cookies = dict_from_cookiejar(self.cookiejar)196-197-198- # response.cookies = dict_from_cookiejar(self.cookiejar)199-200- # response.cookies = dict_from_cookiejar(self.cookiejar)201-132 except AttributeError:133 pass134 135 if is_error:248 unmodified lines384 raise RuntimeError(385 'The content for this response was already consumed')386 387 # Read the contents.458- # print self.raw.__dict__459-460- # print461- # print '~'462- # # print self.raw463- # print self.raw.getresponse()464- # print dir(self.raw)465- # print466- # print467- # print468-469- # self.raw.read() or388 self._content = self.raw.read() or self.raw.data471- # print self.raw.__dict__389 390 # Decode GZip'd content.391 if 'gzip' in self.headers.get('content-encoding', ''):392 try:25 unmodified lines418 raise Exception('400 yo')419 420 elif (self.status_code >= 500) and (self.status_code < 600):421 raise Exception('500 yo')505-506-507-class AuthObject(object):508- """The :class:`AuthObject` is a simple HTTP Authentication token.509-510- 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.513-514- :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- """519-520- _handlers = {521- # 'basic': HTTPBasicAuthHandler,522- # 'forced_basic': HTTPForcedBasicAuthHandler,523- # 'digest': HTTPDigestAuthHandler,524- # 'proxy_basic': urllib2.ProxyBasicAuthHandler,525- # 'proxy_digest': urllib2.ProxyDigestAuthHandler526- }527-528- def __init__(self, username, password, handler='forced_basic', realm=None):529- self.username = username530- self.password = password531- self.realm = realm532-533- if isinstance(handler, basestring):534- self.handler = self._handlers.get(handler.lower(), HTTPForcedBasicAuthHandler)535- else:536- self.handler = handler