Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha-pgp@silbe.org>2013-06-01 10:02:36 (GMT)
committer Sascha Silbe <sascha-pgp@silbe.org>2013-06-01 10:02:36 (GMT)
commit6cbc55666a045c802c1b42c14a5ba950cb561ce7 (patch)
tree53291701c680b235ba94ce0f7ef62129df39b86a
parentb5e8739ab65e0ea9d903a2a6900ea4277554b4ed (diff)
Add support for pywebdav 0.9.8+
pywebdav was restructed in 0.9.8. Try the new names first and fall back to the old ones. Also adjust a few places where compatibility was broken by upstream without notice. While we try to retain compatibility with previous versions of pywebdav, this was only tested with pywebdav 0.9.8.
-rwxr-xr-xjournal2webdav48
1 files changed, 31 insertions, 17 deletions
diff --git a/journal2webdav b/journal2webdav
index f091794..f8b7d88 100755
--- a/journal2webdav
+++ b/journal2webdav
@@ -24,12 +24,24 @@ import time
import urllib
from urlparse import urljoin, urlparse
-import DAV
-import DAV.propfind
-from DAV.constants import COLLECTION, OBJECT
-from DAV.iface import dav_interface
-from DAV.errors import DAV_Error, DAV_NotFound, DAV_Requested_Range_Not_Satisfiable
-from DAVServer.fileauth import DAVAuthHandler
+try:
+ import pywebdav.lib as DAV
+except ImportError:
+ # old names
+ import DAV
+ from DAV import propfind
+ from DAV.constants import COLLECTION, OBJECT
+ from DAV.iface import dav_interface
+ from DAV.errors import DAV_Error, DAV_NotFound, DAV_Requested_Range_Not_Satisfiable
+ from DAVServer.fileauth import DAVAuthHandler
+else:
+ from pywebdav.lib import propfind
+ from pywebdav.lib.constants import COLLECTION, OBJECT
+ from pywebdav.lib.iface import dav_interface
+ from pywebdav.lib.errors import DAV_Error, DAV_NotFound, DAV_Requested_Range_Not_Satisfiable
+ from pywebdav.lib.WebDAVServer import DAVRequestHandler as DAVAuthHandler
+
+# from sugar.logger import trace
import fsemulation
@@ -54,7 +66,7 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
"""Handle requests in a separate thread."""
-class PROPFIND(DAV.propfind.PROPFIND):
+class PROPFIND(propfind.PROPFIND):
# pylint: disable=C0324,C0322
def mk_propname_response(self,uri,propnames,doc):
# copy of original, but with bug fix for multiple namespaces
@@ -205,8 +217,9 @@ class JournalHandler(dav_interface):
def __init__(self, file_system, base_uri, verbose=False):
self._fs = file_system
- # required by dav_interface
+ # required by dav_interface resp. PROPFIND
self.baseuri = base_uri
+ self.baseurl = base_uri
self.verbose = verbose
def exists(self, uri):
@@ -250,12 +263,13 @@ class JournalHandler(dav_interface):
# binary data (e.g. PNG previews)
- # FIXME: We can't add an XML element containing a text node since
- # the xml.dom.minidom implementation requires the Document object
- # for instantiating Nodes, but DAV.propfind.PROPFIND does not pass
- # the Document object down (and there's not even private API to
- # access it as it's a local variable). So the only thing we can
- # return is a plain string.
+ # FIXME: We can't add an XML element containing a text
+ # node since the xml.dom.minidom implementation requires
+ # the Document object for instantiating Nodes, but
+ # propfind.PROPFIND does not pass the Document object down
+ # (and there's not even private API to access it as it's a
+ # local variable). So the only thing we can return is a
+ # plain string.
#element = document.Element('base64Binary', SCHEMA_NS)
#text_node = document.createTextNode(value.encode('base64'))
#element.appendChild(text_node)
@@ -448,7 +462,7 @@ class RequestHandler(DAVAuthHandler):
DATA = DATA.replace('<ns0:creationdate xmlns:ns0="DAV:">',
'<ns0:creationdate xmlns:n="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" b:dt="dateTime.tz">')
- self.send_body_chunks_if_http11(DATA, '207','Multi-Status','Multiple responses')
+ self.send_body_chunks_if_http11(DATA, 207,'Multi-Status','Multiple responses')
def log_message(self, format, *args):
# pylint: disable=W0622
@@ -482,7 +496,7 @@ def main(my_name, args):
root_query = eval(options.root_query)
if options.debug:
- logging.basicConfig(level=logging.DEBUG)
+ logging.basicConfig(level=0)
elif options.verbose:
logging.basicConfig(level=logging.INFO)
else:
@@ -492,7 +506,7 @@ def main(my_name, args):
emulated_fs = fsemulation.FSEmulation(root_query)
handler = RequestHandler
- base_url = 'http://%s:%d/' % (options.host, options.port)
+ base_url = 'http://%s:%d' % (options.host, options.port)
handler.IFACE_CLASS = JournalHandler(emulated_fs, base_url, options.debug)
handler.DO_AUTH = False
handler.IFACE_CLASS.mimecheck = True # pylint: disable=W0201