Allow an auth object to be passed when connecting

This means other authentication methods can be used, e.g. digest
or NTLM, by simply constructing one of the relevant auth objects
supplied with the Requests library.
master
Ciaran Gultnieks 2012-11-13 08:59:46 +00:00
parent 13c98a464f
commit 8159e85172
1 changed files with 4 additions and 2 deletions

View File

@ -61,14 +61,16 @@ class OperationFailed(WebdavException):
super(OperationFailed, self).__init__(msg)
class Client(object):
def __init__(self, host, port=0, username=None, password=None,
def __init__(self, host, port=0, auth=None, username=None, password=None,
protocol='http'):
if not port:
port = 443 if protocol == 'https' else 80
self.baseurl = '{0}://{1}:{2}'.format(protocol, host ,port)
self.cwd = '/'
self.session = requests.session()
if username and password:
if auth:
self.session.auth = auth
elif username and password:
self.session.auth = (username, password)
def _send(self, method, path, expected_code, **kwargs):
url = self._get_url(path)