Skip to content
Myr

prettier imports

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 ccb7fdd · Browse files · 2 files+27 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+27 added−1 removed

  • other:+27 added−1 removed

2 files+27 added−1 removed

modified:requests/async.py+2 added
11 unmodified lines
12"""131415from __future__ import absolute_import1617import urllib18import urllib21920from urllib2 import HTTPError212223try:
25 unmodified lines
modified:requests/core.py+25 added-1 removed
9 unmodified lines
10 :license: ISC, see LICENSE for more details.11"""1213from __future__ import absolute_import1415import urllib16import urllib21718from urllib2 import HTTPError1920from .packages.poster.encode import multipart_encode21from .packages.poster.streaminghttp import register_openers, get_handlers22232425__title__ = 'requests'26__version__ = '0.3.0'27__build__ = 0x00030028__author__ = 'Kenneth Reitz'
6 unmodified lines
35 'URLRequired', 'InvalidMethod', 'HTTPError'36]37383940class _Request(urllib2.Request):41 """Hidden wrapper around the urllib2.Request object. Allows for manual42 setting of HTTP methods.43 """
43 unmodified lines
8788 def __repr__(self):89 return '<Request [%s]>' % (self.method)909192 def __setattr__(self, name, value):93 if (name == 'method') and (value):94 if not value in self._METHODS:95 raise InvalidMethod()9697 object.__setattr__(self, name, value)9899100 def _checks(self):101 """Deterministic checks for consistency."""102103 if not self.url:104 raise URLRequired105106107 def _get_opener(self):108 """Creates appropriate opener object for urllib2."""109110 _handlers = []
71 unmodified lines
182183 return self.sent184185186 187class Response(object):188 """The :class:`Request` object. All :class:`Request` objects contain a189 :class:`Request.response <response>` attribute, which is an instance of190 this class.
7 unmodified lines
198 self.ok = False199 self.error = None200 self.cached = False201202203 def __repr__(self):204 return '<Response [%s]>' % (self.status_code)205206207 def __nonzero__(self):208 """Returns true if status_code is 'OK'."""209 return not self.error210211212 def raise_for_status(self):213 """Raises stored HTTPError if one exists."""214 if self.error:215 raise self.error
11 unmodified lines
227 cls.__singleton__ = singleton = object.__new__(cls)228229 return singleton230231232 def __init__(self):233 self.passwd = {}234 self._auth = {}223 235236237 def __repr__(self):238 return '<AuthManager [%s]>' % (self.method)239240241 def add_auth(self, uri, auth):242 """Registers AuthObject to AuthManager."""243 244 uri = self.reduce_uri(uri, False)
10 unmodified lines
255 if reduced_uri not in self.passwd:256 self.passwd[reduced_uri] = {}257 self.passwd[reduced_uri] = (user, passwd)258259260 def find_user_password(self, realm, authuri):261 for uris, authinfo in self.passwd.iteritems():262 reduced_authuri = self.reduce_uri(authuri, False)263 for uri in uris:
1 unmodified line
265 return authinfo266267 return (None, None)268269270 def get_auth(self, uri):271 uri = self.reduce_uri(uri, False)272 return self._auth.get(uri, None)273274275 def reduce_uri(self, uri, default_port=True):276 """Accept authority or URI and extract only the authority and path."""277 # note HTTP URLs do not have a userinfo component278 parts = urllib2.urlparse.urlsplit(uri)
15 unmodified lines
294 if dport is not None:295 authority = "%s:%d" % (host, dport)296 return authority, path297298 299 def is_suburi(self, base, test):300 """Check if test is below base in a URI tree301302 Both args must be URIs in reduced form.
6 unmodified lines
309 if len(common) == len(base[1]):310 return True311 return False312313314 def empty(self):315 self.passwd = {}316317318 def remove(self, uri, realm=None):319 # uri could be a single URI or a sequence320 if isinstance(uri, basestring):321 uri = [uri]
1 unmodified line
323 for default_port in True, False:324 reduced_uri = tuple([self.reduce_uri(u, default_port) for u in uri])325 del self.passwd[reduced_uri][realm]326327328 def __contains__(self, uri):329 # uri could be a single URI or a sequence330 if isinstance(uri, basestring):331 uri = [uri]
7 unmodified lines
339340auth_manager = AuthManager()341342343344class AuthObject(object):345 """The :class:`AuthObject` is a simple HTTP Authentication token. When346 given to a Requests function, it enables Basic HTTP Authentication for that347 Request. You can also enable Authorization for domain realms with AutoAuth.
22 unmodified lines
370 else:371 self.handler = handler372373374375376def request(method, url, **kwargs):377 """Sends a `method` request. Returns :class:`Response` object.378379 :param method: method for the new :class:`Request` object.
98 unmodified lines