Skip to content
Myr

AutoAuth documentation.

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 e796aae · Browse files · 1 file+19 added−0 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+19 added−0 removed

  • other:+19 added−0 removed

1 file+19 added−0 removed

modified:requests/core.py+19 added
342 unmodified lines
343 return r.response344345346def add_autoauth(url, authobject):347 """Registers given AuthObject to given URL domain. for auto-activation.348 Once a URL is registered with an AuthObject, the configured HTTP349 Authentication will be used for all requests with URLS containing the given350 URL string.351352 Example: ::353 >>> c_auth = requests.AuthObject('kennethreitz', 'xxxxxxx')354 >>> requests.add_autoauth('https://convore.com/api/', c_auth)355 >>> r = requests.get('https://convore.com/api/account/verify.json')356 # Automatically HTTP Authenticated! Wh00t!357358 :param url: Base URL for given AuthObject to auto-activate for.359 :param authobject: AuthObject to auto-activate.360 """361 global AUTOAUTHS362 363 AUTOAUTHS.append((url, authobject))364365366def _detect_auth(url, auth):367 """Returns registered AuthObject for given url if available, defaulting to368 given AuthObject."""369370 return _get_autoauth(url) if not auth else auth371372 373def _get_autoauth(url):374 """Returns registered AuthObject for given url if available.375 """376 377 for (autoauth_url, auth) in AUTOAUTHS:378 if autoauth_url in url: 379 return auth380
13 unmodified lines