AutoAuth documentation.
authorKenneth Reitz <me@kennethreitz.com>
Mon, 14 Feb 2011 04:35:43 +0000 (23:35 -0500)
committerKenneth Reitz <me@kennethreitz.com>
Mon, 14 Feb 2011 04:35:43 +0000 (23:35 -0500)
requests/core.py

index a9f68b9949850368b2c7a84f35b8bce2f67522d3..46e370c27af18947e25b4daf5e9bc870f79e8780 100644 (file)
@@ -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