basic handling configuration in place w/ autoauth
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 54240b4 · Browse files · 1 file·+43 added−9 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+43 added−9 removed
- other:+43 added−9 removed
Provenance
- Commit
ef9bae8- Tree
b125836- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
54240b4
1 file changed+43 added−9 removed
modified:requests/core.py+43 added-9 removed
12 unmodified lines13 import httplib14 import urllib15 import urllib216 17+import requests.handler18 18-19-__title__ = 'convore'19+__title__ = 'requests'20 __version__ = '0.0.1'21 __build__ = 0x00000122 __author__ = 'Kenneth Reitz'23 __license__ = 'ISC'6 unmodified lines30 class Request(object):31 """The :class:`Request` object. It's awesome.32 """33 34- _METHODS = ('get', 'put', 'post', 'delete')34+ _METHODS = ('get', 'head', 'put', 'post', 'delete')35 36 def __init__(self):37 self.headers = dict()38 self.method = None39 self.response = None40+ self.auth = None41 42 def __setattr__(self, key, val):43 if key == 'method':44 if not val.lower() in _METHODS:2 unmodified lines47 def send(self):48 """Sends the request. """49 #set self.response50 # return True / False50- pass51 52- 52+53 class Response(object):54 """The :class:`Request` object. It's awesome.55 """56 14 unmodified lines71 self.username = username72 self.password = password73 74 75+76 def get(url, params={}, headers={}, auth=None):76- pass77+ """Sends a GET request. Returns :class:`Response` object.78+ """79+ r = Request()80+ 81+ r.url = url82+ r.headers = headers83+ r.auth = _detect_auth(url, auth)84+ r.method = 'GET'85+ r.send()86+ 87+ return r.response88+ 89 # return response object90 91+92 def head(url, params={}, headers={}, auth=None):93+ """Sends a HEAD request. Returns :class:`Response` object.94+ """95 pass96 # return response object97 98+99 def post(url, params={}, headers={}, auth=None):100+ """Sends a POST request. Returns :class:`Response` object.101+ """102 pass103 # return response object104 105+ 106 def put(url, data='', headers={}, auth=None):107+ """Sends a PUT request. Returns :class:`Response` object.108+ """109 pass110 # return response object111+112 113 def delete(url, params={}, headers={}, auth=None):114+ """Sends a DELETE request. Returns :class:`Response` object.115+ """116 pass117 # return response object118 119 120 def add_autoauth(url, authobject):97- global AUTHOAUTHS121+ global AUTOAUTHS122 99- AUTHOAUTHS.append((url, authobject))100- 123+ AUTOAUTHS.append((url, authobject))124 125 126+def _detect_auth(url, auth):127 128+ return _get_autoauth(url) if not auth else auth129+130+ 131+def _get_autoauth(url):132+ for (authauth_url, auth) in AUTOAUTHS:133+ if autoauth_url in url: 134+ return auth135+ 136+ return None137+138 class RequestException(Exception):139 """There was an ambiguous exception that occured while handling your request."""140 141 class AuthenticationError(RequestException):8 unmodified lines