[CalendarServer-changes] [5885] CalendarServer/branches/new-store/txcaldav

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 13 14:51:44 PDT 2010


Revision: 5885
          http://trac.macosforge.org/projects/calendarserver/changeset/5885
Author:   glyph at apple.com
Date:     2010-07-13 14:51:43 -0700 (Tue, 13 Jul 2010)
Log Message:
-----------
backend attachment deletion

(plus a minor fix for the contentType test, since PCData compares equal to its string content!)

Modified Paths:
--------------
    CalendarServer/branches/new-store/txcaldav/calendarstore/file.py
    CalendarServer/branches/new-store/txcaldav/calendarstore/test/common.py
    CalendarServer/branches/new-store/txcaldav/icalendarstore.py

Modified: CalendarServer/branches/new-store/txcaldav/calendarstore/file.py
===================================================================
--- CalendarServer/branches/new-store/txcaldav/calendarstore/file.py	2010-07-13 20:06:15 UTC (rev 5884)
+++ CalendarServer/branches/new-store/txcaldav/calendarstore/file.py	2010-07-13 21:51:43 UTC (rev 5885)
@@ -252,7 +252,7 @@
                 fh.write(str(component))
             finally:
                 fh.close()
-                
+
             # Now re-write the original properties on the updated file
             self.properties().flush()
 
@@ -322,14 +322,22 @@
 
     def createAttachmentWithName(self, name, contentType):
         """
-        
+        Implement L{ICalendarObject.removeAttachmentWithName}.
         """
-        # Make a (temp, remember rollbacks) file in dropbox-land
+        # Make a (FIXME: temp, remember rollbacks) file in dropbox-land
         attachment = Attachment(self, name)
         self._attachments[name] = attachment
         return attachment.store(contentType)
 
 
+    def removeAttachmentWithName(self, name):
+        """
+        Implement L{ICalendarObject.removeAttachmentWithName}.
+        """
+        # FIXME: rollback, tests for rollback
+        self._dropboxPath().child(name).remove()
+
+
     def attachmentWithName(self, name):
         # Attachments can be local or remote, but right now we only care about
         # local.  So we're going to base this on the listing of files in the
@@ -431,7 +439,12 @@
 
 class Attachment(object):
     """
-    
+    An L{Attachment} is a container for the data associated with a I{locally-
+    stored} calendar attachment.  That is to say, there will only be
+    L{Attachment} objects present on the I{organizer's} copy of and event, and
+    only for C{ATTACH} properties where this server is storing the resource.
+    (For example, the organizer may specify an C{ATTACH} property that
+    references an URI on a remote server.)
     """
 
     implements(IAttachment)
@@ -461,7 +474,6 @@
 
 
     def contentType(self):
-        # FIXME: tests    
         return self._properties()[contentTypeKey].children[0].data
 
 
@@ -476,8 +488,9 @@
     def retrieve(self, protocol):
         # FIXME: makeConnection
         # FIXME: actually stream
+        # FIMXE: connectionLost
         protocol.dataReceived(self._computePath().getContent())
-        # FIXME: ConnectionDone
+        # FIXME: ConnectionDone, not NotImplementedError
         protocol.connectionLost(Failure(NotImplementedError()))
 
 

Modified: CalendarServer/branches/new-store/txcaldav/calendarstore/test/common.py
===================================================================
--- CalendarServer/branches/new-store/txcaldav/calendarstore/test/common.py	2010-07-13 20:06:15 UTC (rev 5884)
+++ CalendarServer/branches/new-store/txcaldav/calendarstore/test/common.py	2010-07-13 21:51:43 UTC (rev 5885)
@@ -935,7 +935,9 @@
         attachment.retrieve(capture)
         data = yield capture.deferred
         self.assertEquals(data, "new attachment text")
-        self.assertEquals(attachment.contentType(), "text/x-fixture")
+        contentType = attachment.contentType()
+        self.assertIsInstance(contentType, str)
+        self.assertEquals(contentType, "text/x-fixture")
         self.assertEquals(attachment.md5(), '50a9f27aeed9247a0833f30a631f1858')
         self.assertEquals(
             [attachment.name() for attachment in obj.attachments()],
@@ -964,6 +966,33 @@
         return self.createAttachmentTest(refresh)
 
 
+    def test_removeAttachmentWithName(self, refresh=lambda x:x):
+        """
+        L{ICalendarObject.removeAttachmentWithName} will remove the calendar
+        object with the given name.
+        """
+        def deleteIt(ignored):
+            obj = self.calendarObjectUnderTest()
+            obj.removeAttachmentWithName("new.attachment")
+            obj = refresh(obj)
+            self.assertIdentical(
+                None, obj.attachmentWithName("new.attachment")
+            )
+            self.assertEquals(list(obj.attachments()), [])
+        return self.test_createAttachmentCommit().addCallback(deleteIt)
+
+
+    def test_removeAttachmentWithNameCommit(self):
+        """
+        L{ICalendarObject.removeAttachmentWithName} will remove the calendar
+        object with the given name.  (After commit, it will still be gone.)
+        """
+        def refresh(obj):
+            self.commit()
+            return self.calendarObjectUnderTest()
+        return self.test_removeAttachmentWithName(refresh)
+
+
     def test_noDropboxCalendar(self):
         """
         L{ICalendarObject.createAttachmentWithName} may create a directory

Modified: CalendarServer/branches/new-store/txcaldav/icalendarstore.py
===================================================================
--- CalendarServer/branches/new-store/txcaldav/icalendarstore.py	2010-07-13 20:06:15 UTC (rev 5884)
+++ CalendarServer/branches/new-store/txcaldav/icalendarstore.py	2010-07-13 21:51:43 UTC (rev 5885)
@@ -391,7 +391,17 @@
         """
 
 
+    def removeAttachmentWithName(name):
+        """
+        Delete an attachment with the given name.
 
+        @param name: The basename of the attachment (i.e. the last segment of
+            its URI) as given to L{attachmentWithName}.
+        @type name: C{str}
+        """
+
+
+
 class IAttachment(Interface):
     """
     Information associated with an attachment to a calendar object.
@@ -400,27 +410,31 @@
     def name():
         """
         A short name, unique to this attachment's L{ICalendarObject}.
+
+        @rtype: C{str}
         """
 
 
     def contentType():
         """
         A slash-separated content type of the body of this attachment.
+
+        @rtype: C{str}
         """
 
 
     def md5():
         """
-        The MD5 hash of this attachment's contents.
+        The MD5 hex digest of this attachment's contents.
+
+        @rtype: C{str}
         """
-        # Needed to compute the etag, and possibly the 'getcontentmd5'
-        # property.  Possibly need this on other stuff too; it shouldn't really
-        # be exposed in the interface as a dead property.
 
 
     def store(contentType):
         """
         @param contentType: The content type of the data which will be stored.
+        @type contentType: C{str}
 
         @return: An L{ITransport}/L{IConsumer} provider that will store the
             bytes passed to its 'write' method.
@@ -439,9 +453,12 @@
 
     def retrieve(protocol):
         """
+        Retrieve the content of this attachment into a protocol instance.
+
         @param protocol: A protocol which will receive the contents of the
             attachment to its C{dataReceived} method, and then a notification
             that the stream is complete to its C{connectionLost} method.
+        @type protocol: L{IProtocol}
         """
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100713/91cd3288/attachment-0001.html>


More information about the calendarserver-changes mailing list