From: Kenneth Reitz Date: Mon, 14 Feb 2011 04:35:43 +0000 (-0500) Subject: AutoAuth documentation. X-Git-Tag: v0.2.0~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e403a8a42c3fb94e95c48e71fdb944811a2b45f4;p=services%2Fpython-requests.git AutoAuth documentation. --- diff --git a/requests/core.py b/requests/core.py index a9f68b9..46e370c 100644 --- a/requests/core.py +++ b/requests/core.py @@ -344,17 +344,36 @@ def delete(url, params={}, headers={}, auth=None): def add_autoauth(url, authobject): + """Registers given AuthObject to given URL domain. for auto-activation. + Once a URL is registered with an AuthObject, the configured HTTP + Authentication will be used for all requests with URLS containing the given + URL string. + + Example: :: + >>> c_auth = requests.AuthObject('kennethreitz', 'xxxxxxx') + >>> requests.add_autoauth('https://convore.com/api/', c_auth) + >>> r = requests.get('https://convore.com/api/account/verify.json') + # Automatically HTTP Authenticated! Wh00t! + + :param url: Base URL for given AuthObject to auto-activate for. + :param authobject: AuthObject to auto-activate. + """ global AUTOAUTHS AUTOAUTHS.append((url, authobject)) def _detect_auth(url, auth): + """Returns registered AuthObject for given url if available, defaulting to + given AuthObject.""" return _get_autoauth(url) if not auth else auth def _get_autoauth(url): + """Returns registered AuthObject for given url if available. + """ + for (autoauth_url, auth) in AUTOAUTHS: if autoauth_url in url: return auth