[CalendarServer-changes] [7605] CalendarServer/branches/users/glyph/quota/txdav/caldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 20 11:41:45 PDT 2011


Revision: 7605
          http://trac.macosforge.org/projects/calendarserver/changeset/7605
Author:   glyph at apple.com
Date:     2011-06-20 11:41:45 -0700 (Mon, 20 Jun 2011)
Log Message:
-----------
document IAttachmentStorageTransport instead of vague claims in store().

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/file.py
    CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py
    CalendarServer/branches/users/glyph/quota/txdav/caldav/icalendarstore.py

Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/file.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/file.py	2011-06-20 18:40:03 UTC (rev 7604)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/file.py	2011-06-20 18:41:45 UTC (rev 7605)
@@ -32,7 +32,7 @@
 from errno import ENOENT
 
 from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.internet.interfaces import ITransport
+
 from twisted.python.failure import Failure
 
 from txdav.base.propertystore.xattr import PropertyStore
@@ -58,6 +58,7 @@
     validateCalendarComponent, dropboxIDFromCalendarObject, CalendarObjectBase
 )
 
+from txdav.caldav.icalendarstore import IAttachmentStorageTransport
 from txdav.common.datastore.file import (
     CommonDataStore, CommonStoreTransaction, CommonHome, CommonHomeChild,
     CommonObjectResource, CommonStubResource)
@@ -579,7 +580,7 @@
 
 class AttachmentStorageTransport(object):
 
-    implements(ITransport)
+    implements(IAttachmentStorageTransport)
 
     def __init__(self, attachment, contentType):
         """
@@ -600,7 +601,7 @@
 
 
     def loseConnection(self):
-        
+
         old_size = self._attachment.size()
 
         # FIXME: do anything
@@ -608,11 +609,15 @@
 
         md5 = hashlib.md5(self._attachment._path.getContent()).hexdigest()
         props = self._attachment.properties()
-        props[contentTypeKey] = GETContentType(generateContentType(self._contentType))
+        props[contentTypeKey] = GETContentType(
+            generateContentType(self._contentType)
+        )
         props[md5key] = TwistedGETContentMD5.fromString(md5)
 
         # Adjust quota
-        self._attachment._calendarObject._calendar._home.adjustQuotaUsedBytes(self._attachment.size() - old_size)
+        self._attachment._calendarObject._calendar._home.adjustQuotaUsedBytes(
+            self._attachment.size() - old_size
+        )
         props.flush()
 
 

Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py	2011-06-20 18:40:03 UTC (rev 7604)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py	2011-06-20 18:41:45 UTC (rev 7605)
@@ -31,7 +31,6 @@
 
 from twisted.internet.defer import inlineCallbacks, returnValue
 from twisted.internet.error import ConnectionLost
-from twisted.internet.interfaces import ITransport
 from twisted.python import hashlib
 from twisted.python.failure import Failure
 
@@ -69,6 +68,7 @@
 from twext.enterprise.dal.syntax import Len
 
 from txdav.caldav.datastore.util import CalendarObjectBase
+from txdav.caldav.icalendarstore import IAttachmentStorageTransport
 from txdav.common.icommondatastore import IndexedSearchException
 
 from pycalendar.datetime import PyCalendarDateTime
@@ -733,9 +733,11 @@
         """
         return MimeType.fromString("text/calendar; charset=utf-8")
 
+
+
 class AttachmentStorageTransport(object):
 
-    implements(ITransport)
+    implements(IAttachmentStorageTransport)
 
     def __init__(self, attachment, contentType):
         self.attachment = attachment

Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/icalendarstore.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/icalendarstore.py	2011-06-20 18:40:03 UTC (rev 7604)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/icalendarstore.py	2011-06-20 18:41:45 UTC (rev 7605)
@@ -23,18 +23,31 @@
     IShareableCollection
 from txdav.idav import IDataStoreObject, IDataStore
 
+from twisted.internet.interfaces import ITransport
+from twisted.internet.interfaces import IConsumer
 from txdav.idav import INotifier
 
 
 __all__ = [
-    # Classes
+    # Interfaces
     "ICalendarTransaction",
     "ICalendarHome",
     "ICalendar",
     "ICalendarObject",
+
+    # Exceptions
+    "QuotaExceeded",
 ]
 
 
+
+class QuotaExceeded(Exception):
+    """
+    The quota for a particular user has been exceeded.
+    """
+
+
+
 class ICalendarTransaction(ICommonTransaction):
     """
     Transaction functionality required to be implemented by calendar stores.
@@ -171,7 +184,14 @@
 
     def adjustQuotaUsedBytes(delta):
         """
-        Increase the number of bytes that count towards the user's quota.
+        Increase or decrease the number of bytes that count towards the user's
+        quota.
+
+        @param delta: The number of bytes to adjust the quota by.
+
+        @type delta: C{int}
+
+        @raise QuotaExceeded: when the quota is exceeded.
         """
 
 
@@ -432,6 +452,34 @@
 
 
 
+class IAttachmentStorageTransport(ITransport, IConsumer):
+    """
+    An L{IAttachmentStorageTransport} is a transport which stores the bytes
+    written to in a calendar attachment.
+
+    The user of an L{IAttachmentStorageTransport} must call C{loseConnection} on
+    its result to indicate that the attachment upload was successfully
+    completed.  If the transaction associated with this upload is committed or
+    aborted before C{loseConnection} is called, the upload will be presumed to
+    have failed, and no attachment data will be stored.
+    """
+
+    def loseConnection(reason):
+        """
+        The attachment has completed being uploaded successfully.
+
+        Unlike L{ITransport.loseConnection}, which returns C{None}, providers of
+        L{IAttachmentStorageTransport} must return a L{Deferred} from
+        C{loseConnection}, which may fire with a few different types of error;
+        for example, it may fail with a L{QuotaExceeded}.
+
+        If the upload fails for some reason, the transaction should be
+        terminated with L{ICalendarTransaction.abort} and this method should
+        never be called.
+        """
+
+
+
 class IAttachment(IDataStoreObject):
     """
     Information associated with an attachment to a calendar object.
@@ -439,17 +487,15 @@
 
     def store(contentType):
         """
+        Store an attachment (of the given MIME content/type).
+
         @param contentType: The content type of the data which will be stored.
+
         @type contentType: L{twext.web2.http_headers.MimeType}
 
-        @return: An L{ITransport}/L{IConsumer} provider that will store the
-            bytes passed to its 'write' method.
+        @return: A transport which stores the contents written to it.
 
-            The caller of C{store} must call C{loseConnection} on its result to
-            indicate that the attachment upload was successfully completed.  If
-            the transaction associated with this upload is committed or aborted
-            before C{loseConnection} is called, the upload will be presumed to
-            have failed, and no attachment data will be stored.
+        @rtype: L{IAttachmentStorageTransport}
         """
         # If you do a big write()/loseConnection(), how do you tell when the
         # data has actually been written?  you don't: commit() ought to return
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110620/9817d109/attachment-0001.html>


More information about the calendarserver-changes mailing list