Package: python-davlib
Version: 1.8-4

Hi,

It seems to me that the HTTPConnectionAuth class doesn't actually
implement authorization, despite its name and methods. You can work
around this using extra_hdrs which includes an 'Authorization' header,
but because of the inconsistent use of kwargs in the DAV class, this
can be problematic. For instance, you may think, "I will write a class
like this:"

class dav(davlib.DAV):
    def __init__(self):
        davlib.DAV.__init__(self, HOST, PORT)
        self.extra_hdrs = {'Authorization': 'Basic ' +
b64encode(USERNAME + ':' + PASSWORD)}

    def _request(self, method, url, *rest, **kw):
        kw.setdefault('extra_hdrs', {}).update(self.extra_hdrs)
        response = parentDAV._request(self, method, url, *rest, **kw)
        return response

But this will fail if you call one of the random methods in the DAV
class (like 'put', but not 'mkcol') which uses positional arguments to
specify extra headers. Since the DAV class uses positional arguments
and kwargs inconsistently, there's no easy, elegant solution.

Attached is a patch that uses kwargs for all extra_hdrs in internal
calls to _request. Please apply.

Ethan
--- /usr/lib/python2.4/site-packages/davlib.py	2006-06-16 16:43:03.000000000 -0400
+++ davlib.py	2007-05-24 23:17:16.000000000 -0400
@@ -161,7 +161,7 @@
       body = body[1:]
       headers['Content-Type'] = 'application/x-www-form-urlencoded'
 
-    return self._request('POST', url, body, headers)
+    return self._request('POST', url, body, extra_hdrs=headers)
 
   def options(self, url='*', extra_hdrs={ }):
     return self._request('OPTIONS', url, extra_hdrs=extra_hdrs)
@@ -180,7 +180,7 @@
       headers['Content-Type'] = content_type
     if content_enc:
       headers['Content-Encoding'] = content_enc
-    return self._request('PUT', url, contents, headers)
+    return self._request('PUT', url, contents, extra_hdrs=headers)
 
   def delete(self, url, extra_hdrs={ }):
     return self._request('DELETE', url, extra_hdrs=extra_hdrs)
@@ -190,12 +190,12 @@
     headers['Content-Type'] = XML_CONTENT_TYPE
     if depth is not None:
       headers['Depth'] = str(depth)
-    return self._request('PROPFIND', url, body, headers)
+    return self._request('PROPFIND', url, body, extra_hdrs=headers)
 
   def proppatch(self, url, body, extra_hdrs={ }):
     headers = extra_hdrs.copy()
     headers['Content-Type'] = XML_CONTENT_TYPE
-    return self._request('PROPPATCH', url, body, headers)
+    return self._request('PROPPATCH', url, body, extra_hdrs=headers)
 
   def mkcol(self, url, extra_hdrs={ }):
     return self._request('MKCOL', url, extra_hdrs=extra_hdrs)

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to