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
Provenance
- Commit
14ba99f- Tree
ab302ec- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
ccb7fdd
2 files changed+27 added−1 removed
modified:requests/async.py+2 added
11 unmodified lines12 """13 14 15 from __future__ import absolute_import16+17 import urllib18 import urllib219+20 from urllib2 import HTTPError21 22 23 try:25 unmodified linesmodified:requests/core.py+25 added-1 removed
9 unmodified lines10 :license: ISC, see LICENSE for more details.11 """12 13 from __future__ import absolute_import14+15 import urllib16 import urllib217+18 from urllib2 import HTTPError19 20 from .packages.poster.encode import multipart_encode21 from .packages.poster.streaminghttp import register_openers, get_handlers22 23 24+25 __title__ = 'requests'26 __version__ = '0.3.0'27 __build__ = 0x00030028 __author__ = 'Kenneth Reitz'6 unmodified lines35 'URLRequired', 'InvalidMethod', 'HTTPError'36 ]37 38 39+40 class _Request(urllib2.Request):41 """Hidden wrapper around the urllib2.Request object. Allows for manual42 setting of HTTP methods.43 """43 unmodified lines87 88 def __repr__(self):89 return '<Request [%s]>' % (self.method)90 91+92 def __setattr__(self, name, value):93 if (name == 'method') and (value):94 if not value in self._METHODS:95 raise InvalidMethod()96 97 object.__setattr__(self, name, value)98 99+100 def _checks(self):101 """Deterministic checks for consistency."""102 103 if not self.url:104 raise URLRequired105 106+107 def _get_opener(self):108 """Creates appropriate opener object for urllib2."""109 110 _handlers = []71 unmodified lines182 183 return self.sent184 185 186+ 187 class 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 lines198 self.ok = False199 self.error = None200 self.cached = False201 202+203 def __repr__(self):204 return '<Response [%s]>' % (self.status_code)205 206+207 def __nonzero__(self):208 """Returns true if status_code is 'OK'."""209 return not self.error210 211+212 def raise_for_status(self):213 """Raises stored HTTPError if one exists."""214 if self.error:215 raise self.error11 unmodified lines227 cls.__singleton__ = singleton = object.__new__(cls)228 229 return singleton230 231+232 def __init__(self):233 self.passwd = {}234 self._auth = {}223- 235+236+237 def __repr__(self):238 return '<AuthManager [%s]>' % (self.method)239 240+241 def add_auth(self, uri, auth):242 """Registers AuthObject to AuthManager."""243 244 uri = self.reduce_uri(uri, False)10 unmodified lines255 if reduced_uri not in self.passwd:256 self.passwd[reduced_uri] = {}257 self.passwd[reduced_uri] = (user, passwd)258 259+260 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 line265 return authinfo266 267 return (None, None)268 269+270 def get_auth(self, uri):271 uri = self.reduce_uri(uri, False)272 return self._auth.get(uri, None)273 274+275 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 lines294 if dport is not None:295 authority = "%s:%d" % (host, dport)296 return authority, path297 298+ 299 def is_suburi(self, base, test):300 """Check if test is below base in a URI tree301 302 Both args must be URIs in reduced form.6 unmodified lines309 if len(common) == len(base[1]):310 return True311 return False312 313+314 def empty(self):315 self.passwd = {}316 317+318 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 line323 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]326 327+328 def __contains__(self, uri):329 # uri could be a single URI or a sequence330 if isinstance(uri, basestring):331 uri = [uri]7 unmodified lines339 340 auth_manager = AuthManager()341 342 343+344 class 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 lines370 else:371 self.handler = handler372 373 374+375+376 def request(method, url, **kwargs):377 """Sends a `method` request. Returns :class:`Response` object.378 379 :param method: method for the new :class:`Request` object.98 unmodified lines