mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
basic handling configuration in place w/ autoauth
This commit is contained in:
+43
-9
@@ -14,9 +14,9 @@ import httplib
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
import requests.handler
|
||||
|
||||
|
||||
__title__ = 'convore'
|
||||
__title__ = 'requests'
|
||||
__version__ = '0.0.1'
|
||||
__build__ = 0x000001
|
||||
__author__ = 'Kenneth Reitz'
|
||||
@@ -31,12 +31,13 @@ class Request(object):
|
||||
"""The :class:`Request` object. It's awesome.
|
||||
"""
|
||||
|
||||
_METHODS = ('get', 'put', 'post', 'delete')
|
||||
_METHODS = ('get', 'head', 'put', 'post', 'delete')
|
||||
|
||||
def __init__(self):
|
||||
self.headers = dict()
|
||||
self.method = None
|
||||
self.response = None
|
||||
self.auth = None
|
||||
|
||||
def __setattr__(self, key, val):
|
||||
if key == 'method':
|
||||
@@ -47,9 +48,8 @@ class Request(object):
|
||||
"""Sends the request. """
|
||||
#set self.response
|
||||
# return True / False
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class Response(object):
|
||||
"""The :class:`Request` object. It's awesome.
|
||||
"""
|
||||
@@ -72,34 +72,68 @@ class AuthObject(object):
|
||||
self.password = password
|
||||
|
||||
|
||||
|
||||
def get(url, params={}, headers={}, auth=None):
|
||||
pass
|
||||
"""Sends a GET request. Returns :class:`Response` object.
|
||||
"""
|
||||
r = Request()
|
||||
|
||||
r.url = url
|
||||
r.headers = headers
|
||||
r.auth = _detect_auth(url, auth)
|
||||
r.method = 'GET'
|
||||
r.send()
|
||||
|
||||
return r.response
|
||||
|
||||
# return response object
|
||||
|
||||
|
||||
def head(url, params={}, headers={}, auth=None):
|
||||
"""Sends a HEAD request. Returns :class:`Response` object.
|
||||
"""
|
||||
pass
|
||||
# return response object
|
||||
|
||||
|
||||
def post(url, params={}, headers={}, auth=None):
|
||||
"""Sends a POST request. Returns :class:`Response` object.
|
||||
"""
|
||||
pass
|
||||
# return response object
|
||||
|
||||
|
||||
def put(url, data='', headers={}, auth=None):
|
||||
"""Sends a PUT request. Returns :class:`Response` object.
|
||||
"""
|
||||
pass
|
||||
# return response object
|
||||
|
||||
|
||||
def delete(url, params={}, headers={}, auth=None):
|
||||
"""Sends a DELETE request. Returns :class:`Response` object.
|
||||
"""
|
||||
pass
|
||||
# return response object
|
||||
|
||||
|
||||
def add_autoauth(url, authobject):
|
||||
global AUTHOAUTHS
|
||||
|
||||
AUTHOAUTHS.append((url, authobject))
|
||||
global AUTOAUTHS
|
||||
|
||||
AUTOAUTHS.append((url, authobject))
|
||||
|
||||
|
||||
def _detect_auth(url, auth):
|
||||
|
||||
return _get_autoauth(url) if not auth else auth
|
||||
|
||||
|
||||
def _get_autoauth(url):
|
||||
for (authauth_url, auth) in AUTOAUTHS:
|
||||
if autoauth_url in url:
|
||||
return auth
|
||||
|
||||
return None
|
||||
|
||||
class RequestException(Exception):
|
||||
"""There was an ambiguous exception that occured while handling your request."""
|
||||
|
||||
Reference in New Issue
Block a user