From: Kenneth Reitz Date: Sun, 23 Oct 2011 15:33:03 +0000 (-0400) Subject: more advanced authentication mechanism X-Git-Tag: v0.7.1~1^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4892a305d9cd658287b3320d18c60886b14b5b48;p=services%2Fpython-requests.git more advanced authentication mechanism --- diff --git a/requests/auth.py b/requests/auth.py index 3a978b1..6825441 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -28,4 +28,32 @@ def http_digest(r, username, password): Arguments should be considered non-positional. """ - r.headers \ No newline at end of file + r.headers + + +def dispatch(t): + """Given an auth tuple, return an expanded version.""" + + if not t: + return t + else: + t = list(t) + + # Make sure they're passing in something. + assert len(t) <= 2 + + # If only two items are passed in, assume HTTPBasic. + if (len(t) == 2): + t.insert(0, 'basic') + + # Allow built-in string referenced auths. + if isinstance(t[0], basestring): + if t[0] in ('basic', 'forced_basic'): + t[0] = http_basic + elif t[0] in ('digest',): + t[0] = http_digest + + # Return a custom callable. + return (t[0], t[1:]) + +