Skip to content
Myr

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

1 file+43 added−9 removed

modified:requests/core.py+43 added-9 removed
12 unmodified lines
13import httplib14import urllib15import urllib21617import requests.handler181819__title__ = 'convore'19__title__ = 'requests'20__version__ = '0.0.1'21__build__ = 0x00000122__author__ = 'Kenneth Reitz'23__license__ = 'ISC'
6 unmodified lines
30class 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 lines
47 def send(self):48 """Sends the request. """49 #set self.response50 # return True / False50 pass51 52 5253class Response(object):54 """The :class:`Request` object. It's awesome.55 """56
14 unmodified lines
71 self.username = username72 self.password = password73747576def 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 object909192def head(url, params={}, headers={}, auth=None):93 """Sends a HEAD request. Returns :class:`Response` object.94 """95 pass96 # return response object979899def post(url, params={}, headers={}, auth=None):100 """Sends a POST request. Returns :class:`Response` object.101 """102 pass103 # return response object104 105 106def put(url, data='', headers={}, auth=None):107 """Sends a PUT request. Returns :class:`Response` object.108 """109 pass110 # return response object111112 113def delete(url, params={}, headers={}, auth=None):114 """Sends a DELETE request. Returns :class:`Response` object.115 """116 pass117 # return response object118119120def add_autoauth(url, authobject):97 global AUTHOAUTHS121 global AUTOAUTHS122 99 AUTHOAUTHS.append((url, authobject))100 123 AUTOAUTHS.append((url, authobject))124125126def _detect_auth(url, auth):127128 return _get_autoauth(url) if not auth else auth129130 131def _get_autoauth(url):132 for (authauth_url, auth) in AUTOAUTHS:133 if autoauth_url in url: 134 return auth135 136 return None137138class RequestException(Exception):139 """There was an ambiguous exception that occured while handling your request."""140141class AuthenticationError(RequestException):
8 unmodified lines