[Commits] (pavlov) add checks for 404 errors so we don't explode

commits at osafoundation.org commits at osafoundation.org
Tue Aug 17 13:24:07 PDT 2004


Commit by: pavlov
Modified files:
chandler/parcels/osaf/framework/webdav/DAVItem.py 1.4 1.5
chandler/parcels/osaf/framework/webdav/Dav.py 1.6 1.7

Log message:
add checks for 404 errors so we don't explode


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/DAVItem.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Dav.py.diff?r1=text&tr1=1.6&r2=text&tr2=1.7

Index: chandler/parcels/osaf/framework/webdav/DAVItem.py
diff -u chandler/parcels/osaf/framework/webdav/DAVItem.py:1.4 chandler/parcels/osaf/framework/webdav/DAVItem.py:1.5
--- chandler/parcels/osaf/framework/webdav/DAVItem.py:1.4	Mon Aug 16 17:26:42 2004
+++ chandler/parcels/osaf/framework/webdav/DAVItem.py	Tue Aug 17 13:24:05 2004
@@ -4,6 +4,8 @@
 import httplib
 import libxml2
 
+import Dav
+
 class BadItem(Exception):
     pass
 
@@ -46,6 +48,9 @@
         # already.  This might be the best solution.
         r = self.dav.newConnection().propfind(url, body, depth)
 
+        if r.status == 404:
+            raise Dav.NotFound
+
         xmlgoop = r.read()
 
         doc = libxml2.parseDoc(xmlgoop)

Index: chandler/parcels/osaf/framework/webdav/Dav.py
diff -u chandler/parcels/osaf/framework/webdav/Dav.py:1.6 chandler/parcels/osaf/framework/webdav/Dav.py:1.7
--- chandler/parcels/osaf/framework/webdav/Dav.py:1.6	Tue Aug 17 11:42:24 2004
+++ chandler/parcels/osaf/framework/webdav/Dav.py	Tue Aug 17 13:24:05 2004
@@ -12,6 +12,11 @@
    the right thing automatically.  Wouldn't that be nice.
 """
 
+class DAVException(Exception):
+    pass
+class NotFound(DAVException):
+    pass
+
 class DAV(object):
     def __init__(self, resourceURL):
         super(DAV, self).__init__()
@@ -31,7 +36,10 @@
         # return status.. or maybe just throw an exception if the put failed
 
     def getHeaders(self):
-        return self.newConnection().head(unicode(self.url))
+        r = self.newConnection().head(unicode(self.url))
+        if r.status == 404:
+            raise NotFound
+        return r
 
     def _getETag(self):
         return self.getHeaders().getheader('ETag', default='')
@@ -42,14 +50,26 @@
 
     def get(self):
         """ returns a newly created Item """
-        return Sync.getItem(self)
+        try:
+            return Sync.getItem(self)
+        except NotFound:
+            return None
 
     def put(self, item):
         # add an entry here to say that we're already here
         sharing = Globals.repository.findPath('//parcels/osaf/framework/GlobalShare') 
         sharing.itemMap[item.itsUUID] = item.itsUUID
+        
+        if item.hasAttributeValue('sharedURL'):
+            # we only support you sharing to a single URL at the moment
+            # it is an error to try and share to another place..
+            if item.sharedURL != self.url:
+                print 'Warning: trying to share %s to %s' % (unicode(item.sharedURL), unicode(self.url))
+            # for now, force our current url to be the shared url
+            self.url = item.sharedURL
+        else:
+            item.sharedURL = self.url
 
-        item.sharedURL = self.url
         self.sync(item)
 
     def sync(self, item):



More information about the Commits mailing list