[CalendarServer-changes] [2297] CalendarServer/branches/propfind-cache/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 10 14:10:31 PDT 2008


Revision: 2297
          http://trac.macosforge.org/projects/calendarserver/changeset/2297
Author:   dreid at apple.com
Date:     2008-04-10 14:10:30 -0700 (Thu, 10 Apr 2008)

Log Message:
-----------
Removing code is awesome, use the uuid library in the python 2.5 stdlib

Modified Paths:
--------------
    CalendarServer/branches/propfind-cache/twistedcaldav/static.py
    CalendarServer/branches/propfind-cache/twistedcaldav/test/test_static.py

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/static.py	2008-04-10 18:35:28 UTC (rev 2296)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/static.py	2008-04-10 21:10:30 UTC (rev 2297)
@@ -37,6 +37,7 @@
 import datetime
 import os
 import errno
+import uuid
 from urlparse import urlsplit
 
 from twisted.internet.defer import deferredGenerator, fail, succeed, waitForDeferred
@@ -118,9 +119,9 @@
                     responsecode.FORBIDDEN,
                     (caldavxml.caldav_namespace, "calendar-collection-location-ok")
                 ))
-    
+
             return self.createCalendarCollection()
-            
+
         parent = self._checkParents(request, isPseudoCalendarCollectionResource)
         parent.addCallback(_defer)
         return parent
@@ -132,13 +133,13 @@
         def onCalendarCollection(status):
             if status != responsecode.CREATED:
                 raise HTTPError(status)
-    
+
             # Initialize CTag on the calendar collection
             self.updateCTag()
-            
+
             # Create the index so its ready when the first PUTs come in
             self.index().create()
-            
+
             return status
 
         d = self.createSpecialCollection(davxml.ResourceType.calendar)
@@ -152,10 +153,10 @@
         def onCollection(status):
             if status != responsecode.CREATED:
                 raise HTTPError(status)
-    
+
             self.writeDeadProperty(resourceType)
             return status
-        
+
         def onError(f):
             try:
                 rmdir(self.fp)
@@ -168,7 +169,7 @@
             d.addCallback(onCollection)
         d.addErrback(onError)
         return d
- 
+
     def iCalendarRolledup(self, request):
         if self.isPseudoCalendarCollection():
             # Generate a monolithic calendar
@@ -190,7 +191,7 @@
                     child = IDAVResource(child)
                 except TypeError:
                     child = None
-    
+
                 if child is not None:
                     # Check privileges of child - skip if access denied
                     try:
@@ -204,7 +205,7 @@
 
                     for component in subcalendar.subcomponents():
                         calendar.addComponent(component)
-                        
+
             yield calendar
             return
 
@@ -257,7 +258,7 @@
             d = self.locateParent(request, request.urlForResource(self))
             d.addCallback(gotParent)
             return d
-        
+
         return super(CalDAVFile, self).supportedPrivileges(request)
 
     ##
@@ -304,17 +305,17 @@
                 """
                 Recursively descend the directory tree rooted at top,
                 calling the callback function for each regular file
-                
+
                 @param top: L{FilePath} for the directory to walk.
                 """
-            
+
                 total = 0
                 for f in top.listdir():
-    
+
                     # Ignore the database
                     if f.startswith("."):
                         continue
-    
+
                     child = top.child(f)
                     if child.isdir():
                         # It's a directory, recurse into it
@@ -327,11 +328,11 @@
                     else:
                         # Unknown file type, print a message
                         pass
-            
+
                 yield total
-            
+
             walktree = deferredGenerator(walktree)
-    
+
             return walktree(self.fp)
         else:
             return succeed(self.fp.getsize())
@@ -355,20 +356,20 @@
         #
         # Parse the URI
         #
-    
+
         (scheme, host, path, query, fragment) = urlsplit(uri) #@UnusedVariable
-    
+
         # Request hostname and child uri hostname have to be the same.
         if host and host != request.headers.getHeader("host"):
             return False
-        
+
         # Child URI must start with request uri text.
         parent = request.uri
         if not parent.endswith("/"):
             parent += "/"
-            
+
         return path.startswith(parent) and (len(path) > len(parent)) and (not immediateChild or (path.find("/", len(parent)) == -1))
-    
+
     def _checkParents(self, request, test):
         """
         @param request: the request being processed.
@@ -393,7 +394,7 @@
                 return
 
         yield None
-    
+
     _checkParents = deferredGenerator(_checkParents)
 
 class AutoProvisioningFileMixIn (AutoProvisioningResourceMixIn):
@@ -414,7 +415,7 @@
             parent = self.parent
             if not parent.exists() and isinstance(parent, AutoProvisioningFileMixIn):
                 parent.provision()
-                
+
             assert parent.exists(), "Parent %s of %s does not exist" % (parent, self)
             assert parent.isCollection(), "Parent %s of %s is not a collection" % (parent, self)
 
@@ -435,7 +436,7 @@
 
 class CalendarHomeProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeProvisioningResource, DAVFile):
     """
-    Resource which provisions calendar home collections as needed.    
+    Resource which provisions calendar home collections as needed.
     """
     def __init__(self, path, directory, url):
         """
@@ -565,16 +566,8 @@
 
 
     def _newCacheToken(self, property=False, data=False):
-        import ctypes, ctypes.util
-        _uuid = ctypes.create_string_buffer(16)
-        libc = ctypes.CDLL(ctypes.util.find_library('c'))
-        libc.uuid_generate_time(_uuid)
+        return uuid.uuid4()
 
-        uuid = "%032x" % (long("%02x"*16 % tuple(map(ord, _uuid.raw)), 16),)
-        return "%s-%s-%s-%s-%s" % (
-            uuid[:8], uuid[8:12], uuid[12:16], uuid[16:20], uuid[20:])
-
-
     def changed(self, request, uri, properties=False, data=False):
         try:
             oldCacheTokens = self.readDeadProperty(CacheTokensProperty.qname())
@@ -753,9 +746,9 @@
         elements = []
         elements.append(customxml.TimeStamp.fromString(timestamp))
         elements.append(customxml.Changed(davxml.HRef.fromString(parentURL)))
-                          
+
         xml = customxml.Notification(*elements)
-        
+
         d = waitForDeferred(put_common_base.storeResource(request, data=xml.toxml(), destination=self, destination_uri=request.urlForResource(self)))
         yield d
         d.getResult()

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/test/test_static.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/test/test_static.py	2008-04-10 18:35:28 UTC (rev 2296)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/test/test_static.py	2008-04-10 21:10:30 UTC (rev 2297)
@@ -74,6 +74,7 @@
             _newCacheTokenStub,
             self.myCalendarHome,
             CalendarHomeFile)
+
         self.myCalendarHome._newCacheToken(property=True)
         self.myCalendarHome._newCacheToken(data=True)
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080410/5bc82d89/attachment-0001.html


More information about the calendarserver-changes mailing list