Anonymous avatar Anonymous committed 3eaa2a6

Styleish changes :)

Comments (0)

Files changed (1)

heechee/webdav.py

-
 from lxml.etree import fromstring, tostring, Element, SubElement
-from werkzeug import Request, Response
+from werkzeug import Request, Response, cached_property
 from werkzeug.exceptions import HTTPException, MethodNotAllowed, BadRequest
 
 from heechee.svndiff import make_cheap_diff
 SVN_DAV_NS = "{http://subversion.tigris.org/xmlns/dav/}"
 
 
+class DAVRequest(Request):
+
+    @cached_property
+    def xml_body(self):
+        # would be nicer to have fromstring(self.data) but that requires
+        # an unreleased version of Werkzeug.
+        return fromstring(self.input_stream.read(self.content_length))
+
 
 class Application(object):
     
-    verbs = ["OPTIONS", "PROPFIND", "REPORT"]
+    verbs = frozenset(["OPTIONS", "PROPFIND", "REPORT"])
     
     def __init__(self, repo):
         self.repo = repo
     
-    @Request.application
+    @DAVRequest.application
     def __call__(self, request):
         try:
-            if hasattr(self, request.method):
-                return getattr(self, request.method)(request)
-            else:
+            if request.method not in self.verbs:
                 raise MethodNotAllowed(self.verbs)
+            return getattr(self, request.method)(request)
         except HTTPException, e:
             return e
     
         various things about the repo.
         """
         # Do they want the properties of the overall repo?
-        data = request.input_stream.read(request.content_length)
-        tree = fromstring(data)
+        tree = request.xml_body
         
         props = [x.tag.split("}")[-1] for x in tree.find("{DAV:}prop").getchildren()]
         
 
 if __name__ == "__main__":
     from werkzeug import run_simple
-    run_simple('localhost', 8080, Application(Repository()))
+    run_simple('localhost', 8080, Application(Repository()))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.