initial auth module w/ httpbasic auth

This commit is contained in:
Kenneth Reitz
2011-10-23 10:56:04 -04:00
parent b8d4a5ea61
commit 340f7a0733
+29
View File
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
"""
requests.auth
~~~~~~~~~~~~~
This module contains the authentication handlers for Requests.
"""
from base64 import encodestring as base64
def http_basic(r, username, password):
"""Attaches HTTP Basic Authentication to the given Request object.
Arguments should be considered non-positional.
"""
auth_s = base64('%s:%s' % (username, password)).replace('\n', '')
r.headers['Authorization'] = ('Basic %s' % auth_s)
return r
def http_digest(r, username, password):
"""Attaches HTTP Digest Authentication to the given Request object.
Arguments should be considered non-positional.
"""
r.headers