[CalendarServer-changes] [8549] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jan 16 17:47:33 PST 2012
Revision: 8549
http://trac.macosforge.org/projects/calendarserver/changeset/8549
Author: sagen at apple.com
Date: 2012-01-16 17:47:32 -0800 (Mon, 16 Jan 2012)
Log Message:
-----------
Normalize UUID values from directory services; stop auto-generating record.guid if not provided.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/provision/root.py
CalendarServer/trunk/calendarserver/push/applepush.py
CalendarServer/trunk/calendarserver/push/test/test_applepush.py
CalendarServer/trunk/calendarserver/tools/purge.py
CalendarServer/trunk/calendarserver/tools/test/test_purge_old_events.py
CalendarServer/trunk/twistedcaldav/directory/aggregate.py
CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
CalendarServer/trunk/twistedcaldav/directory/cachingdirectory.py
CalendarServer/trunk/twistedcaldav/directory/directory.py
CalendarServer/trunk/twistedcaldav/directory/sudo.py
CalendarServer/trunk/twistedcaldav/directory/test/test_cachedirectory.py
CalendarServer/trunk/twistedcaldav/directory/test/test_directory.py
CalendarServer/trunk/twistedcaldav/directory/test/test_util.py
CalendarServer/trunk/twistedcaldav/directory/util.py
CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
Modified: CalendarServer/trunk/calendarserver/provision/root.py
===================================================================
--- CalendarServer/trunk/calendarserver/provision/root.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/calendarserver/provision/root.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -286,9 +286,9 @@
break
if principal:
- log.debug("Wiki-authenticated principal %s being assigned to authnUser and authzUser" % (record.guid,))
+ log.debug("Wiki-authenticated principal %s being assigned to authnUser and authzUser" % (record.uid,))
request.authzUser = request.authnUser = davxml.Principal(
- davxml.HRef.fromString("/principals/__uids__/%s/" % (record.guid,))
+ davxml.HRef.fromString("/principals/__uids__/%s/" % (record.uid,))
)
if not hasattr(request, "authzUser") and config.WebCalendarAuthPath:
Modified: CalendarServer/trunk/calendarserver/push/applepush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/applepush.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/calendarserver/push/applepush.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -169,8 +169,8 @@
if numSubscriptions > 0:
self.log_debug("Sending %d APNS notifications for %s" %
(numSubscriptions, key))
- for token, guid in subscriptions:
- if token and guid:
+ for token, uid in subscriptions:
+ if token and uid:
provider.sendNotification(token, key)
@@ -474,7 +474,7 @@
txn = self.factory.store.newTransaction()
subscriptions = (yield txn.apnSubscriptionsByToken(token))
- for key, modified, guid in subscriptions:
+ for key, modified, uid in subscriptions:
if timestamp > modified:
self.log_debug("FeedbackProtocol removing subscription: %s %s" %
(token, key))
@@ -631,9 +631,9 @@
else:
principal = self.principalFromRequest(request)
- guid = principal.record.guid
+ uid = principal.record.uid
try:
- yield self.addSubscription(token, key, guid)
+ yield self.addSubscription(token, key, uid)
code = responsecode.OK
msg = None
except InvalidSubscriptionValues:
@@ -643,7 +643,7 @@
returnValue((code, msg))
@inlineCallbacks
- def addSubscription(self, token, key, guid):
+ def addSubscription(self, token, key, uid):
"""
Add a subscription (or update its timestamp if already there).
@@ -653,12 +653,12 @@
@param key: The push key
@type key: C{str}
- @param guid: The GUID of the subscriber principal
- @type guid: C{str}
+ @param uid: The uid of the subscriber principal
+ @type uid: C{str}
"""
now = int(time.time()) # epoch seconds
txn = self.store.newTransaction()
- yield txn.addAPNSubscription(token, key, now, guid)
+ yield txn.addAPNSubscription(token, key, now, uid)
yield txn.commit()
def renderResponse(self, code, body=None):
Modified: CalendarServer/trunk/calendarserver/push/test/test_applepush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/test/test_applepush.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/calendarserver/push/test/test_applepush.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -77,12 +77,12 @@
token = "2d0d55cd7f98bcb81c6e24abcdc35168254c7846a43e2828b1ba5a8f82e219df"
key1 = "/CalDAV/calendars.example.com/user01/calendar/"
timestamp1 = 1000
- guid = "D2256BCC-48E2-42D1-BD89-CBA1E4CCDFFB"
- yield txn.addAPNSubscription(token, key1, timestamp1, guid)
+ uid = "D2256BCC-48E2-42D1-BD89-CBA1E4CCDFFB"
+ yield txn.addAPNSubscription(token, key1, timestamp1, uid)
key2 = "/CalDAV/calendars.example.com/user02/calendar/"
timestamp2 = 3000
- yield txn.addAPNSubscription(token, key2, timestamp2, guid)
+ yield txn.addAPNSubscription(token, key2, timestamp2, uid)
yield txn.commit()
# Set up the service
Modified: CalendarServer/trunk/calendarserver/tools/purge.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/purge.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/calendarserver/tools/purge.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -188,7 +188,7 @@
class PurgePrincipalService(WorkerService):
- guids = None
+ uids = None
dryrun = False
verbose = False
completely = False
@@ -197,7 +197,7 @@
def doWork(self):
rootResource = self.rootResource()
directory = rootResource.getDirectory()
- total = (yield purgeGUIDs(directory, rootResource, self.guids,
+ total = (yield purgeUIDs(directory, rootResource, self.uids,
verbose=self.verbose, dryrun=self.dryrun,
completely=self.completely))
if self.verbose:
@@ -389,8 +389,8 @@
else:
raise NotImplementedError(opt)
- # args is a list of guids
- PurgePrincipalService.guids = args
+ # args is a list of uids
+ PurgePrincipalService.uids = args
PurgePrincipalService.completely = completely
PurgePrincipalService.dryrun = dryrun
PurgePrincipalService.verbose = verbose
@@ -496,14 +496,14 @@
@inlineCallbacks
-def purgeGUIDs(directory, root, guids, verbose=False, dryrun=False,
+def purgeUIDs(directory, root, uids, verbose=False, dryrun=False,
completely=False):
total = 0
allAssignments = { }
- for guid in guids:
- count, allAssignments[guid] = (yield purgeGUID(guid, directory, root,
+ for uid in uids:
+ count, allAssignments[uid] = (yield purgeUID(uid, directory, root,
verbose=verbose, dryrun=dryrun, completely=completely))
total += count
@@ -620,27 +620,27 @@
@inlineCallbacks
-def purgeGUID(guid, directory, root, verbose=False, dryrun=False, proxies=True,
+def purgeUID(uid, directory, root, verbose=False, dryrun=False, proxies=True,
when=None, completely=False):
if when is None:
when = PyCalendarDateTime.getNowUTC()
# Does the record exist?
- record = directory.recordWithGUID(guid)
+ record = directory.recordWithUID(uid)
if record is None:
# The user has already been removed from the directory service. We
# need to fashion a temporary, fake record
# FIXME: probaby want a more elegant way to accomplish this,
# since it requires the aggregate directory to examine these first:
- record = DirectoryRecord(directory, "users", guid, shortNames=(guid,),
+ record = DirectoryRecord(directory, "users", uid, shortNames=(uid,),
enabledForCalendaring=True)
record.enabled = True
- directory._tmpRecords["shortNames"][guid] = record
- directory._tmpRecords["guids"][guid] = record
+ directory._tmpRecords["shortNames"][uid] = record
+ directory._tmpRecords["uids"][uid] = record
- cua = "urn:uuid:%s" % (guid,)
+ cua = "urn:uuid:%s" % (uid,)
principalCollection = directory.principalCollection
principal = principalCollection.principalForRecord(record)
@@ -648,7 +648,7 @@
request = FakeRequest(root, None, None)
request.checkedSACL = True
request.authnUser = request.authzUser = davxml.Principal(
- davxml.HRef.fromString("/principals/__uids__/%s/" % (guid,))
+ davxml.HRef.fromString("/principals/__uids__/%s/" % (uid,))
)
calendarHome = yield principal.calendarHome(request)
@@ -669,7 +669,7 @@
count = 0
assignments = []
- perUserFilter = PerUserDataFilter(guid)
+ perUserFilter = PerUserDataFilter(uid)
for collName in (yield calendarHome.listChildren()):
collection = (yield calendarHome.getChild(collName))
@@ -696,7 +696,7 @@
event = perUserFilter.filter(event)
action = cancelEvent(event, when, cua)
- uri = "/calendars/__uids__/%s/%s/%s" % (guid, collName, childName)
+ uri = "/calendars/__uids__/%s/%s/%s" % (uid, collName, childName)
request.path = uri
if action == CANCELEVENT_MODIFIED:
count += 1
@@ -728,7 +728,7 @@
if not dryrun:
result = (yield childResource.storeRemove(request, True, uri))
if result != NO_CONTENT:
- print "Error deleting %s/%s/%s: %s" % (guid,
+ print "Error deleting %s/%s/%s: %s" % (uid,
collName, childName, result)
@@ -736,7 +736,7 @@
# Remove empty calendar collections (and calendar home if no more
# calendars)
- calHome = (yield txn.calendarHomeWithUID(guid))
+ calHome = (yield txn.calendarHomeWithUID(uid))
if calHome is not None:
calendars = list((yield calHome.calendars()))
remainingCalendars = len(calendars)
@@ -763,13 +763,13 @@
# Remove VCards
- abHome = (yield txn.addressbookHomeWithUID(guid))
+ abHome = (yield txn.addressbookHomeWithUID(uid))
if abHome is not None:
for abColl in list( (yield abHome.addressbooks()) ):
for card in list( (yield abColl.addressbookObjects()) ):
cardName = card.name()
if verbose:
- uri = "/addressbooks/__uids__/%s/%s/%s" % (guid, abColl.name(), cardName)
+ uri = "/addressbooks/__uids__/%s/%s/%s" % (uid, abColl.name(), cardName)
if dryrun:
print "Would delete: %s" % (uri,)
else:
@@ -815,13 +815,13 @@
proxyFor = (yield principal.proxyFor(proxyType == "write"))
for other in proxyFor:
- assignments.append((principal.record.guid, proxyType, other.record.guid))
+ assignments.append((principal.record.uid, proxyType, other.record.uid))
(yield removeProxy(other, principal))
subPrincipal = principal.getChild("calendar-proxy-" + proxyType)
proxies = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
for other in proxies.children:
- assignments.append((str(other).split("/")[3], proxyType, principal.record.guid))
+ assignments.append((str(other).split("/")[3], proxyType, principal.record.uid))
(yield subPrincipal.writeProperty(davxml.GroupMemberSet(), None))
Modified: CalendarServer/trunk/calendarserver/tools/test/test_purge_old_events.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_purge_old_events.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/calendarserver/tools/test/test_purge_old_events.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -18,7 +18,7 @@
Tests for calendarserver.tools.purge
"""
from calendarserver.tap.util import getRootResource
-from calendarserver.tools.purge import purgeOldEvents, purgeGUID, purgeOrphanedAttachments
+from calendarserver.tools.purge import purgeOldEvents, purgeUID, purgeOrphanedAttachments
from twext.web2.http_headers import MimeType
@@ -512,7 +512,7 @@
test_purgeOldEvents.todo = "New lazy indexing broke this"
@inlineCallbacks
- def test_purgeGUID(self):
+ def test_purgeUID(self):
txn = self._sqlCalendarStore.newTransaction()
# Create an addressbook and one CardDAV resource
@@ -527,11 +527,11 @@
calColl = (yield calHome.calendarWithName("calendar1"))
self.assertEquals(len( (yield calColl.calendarObjects()) ), 3)
- # Make the newly created objects available to the purgeGUID transaction
+ # Make the newly created objects available to the purgeUID transaction
(yield txn.commit())
# Purge home1
- total, ignored = (yield purgeGUID("home1", self.directory,
+ total, ignored = (yield purgeUID("home1", self.directory,
self.rootResource, verbose=False, proxies=False,
when=PyCalendarDateTime(2010, 4, 1, 12, 0, 0, 0, PyCalendarTimezone(utc=True))))
@@ -549,7 +549,7 @@
@inlineCallbacks
- def test_purgeGUIDCompletely(self):
+ def test_purgeUIDCompletely(self):
txn = self._sqlCalendarStore.newTransaction()
# Create an addressbook and one CardDAV resource
@@ -564,11 +564,11 @@
calColl = (yield calHome.calendarWithName("calendar1"))
self.assertEquals(len( (yield calColl.calendarObjects()) ), 3)
- # Make the newly created objects available to the purgeGUID transaction
+ # Make the newly created objects available to the purgeUID transaction
(yield txn.commit())
# Purge home1 completely
- total, ignored = (yield purgeGUID("home1", self.directory,
+ total, ignored = (yield purgeUID("home1", self.directory,
self.rootResource, verbose=False, proxies=False, completely=True))
# 4 items deleted: 3 events and 1 vcard
Modified: CalendarServer/trunk/twistedcaldav/directory/aggregate.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/aggregate.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/aggregate.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -72,10 +72,10 @@
# FIXME: This is a temporary workaround until new data store is in
# place. During the purging of deprovisioned users' data, we need
- # to be able to look up records by guid and shortName. The purge
+ # to be able to look up records by uid and shortName. The purge
# tool sticks temporary fake records in here.
self._tmpRecords = {
- "guids" : { },
+ "uids" : { },
"shortNames" : { },
}
@@ -134,7 +134,7 @@
# FIXME: These temporary records shouldn't be needed when we move
# to the new data store API. They're currently needed when purging
# deprovisioned users' data.
- record = self._tmpRecords["guids"].get(uid, None)
+ record = self._tmpRecords["uids"].get(uid, None)
if record:
return record
Modified: CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -714,12 +714,8 @@
self.INDEX_TYPE_AUTHID : dsattributes.kDSNAttrAltSecurityIdentities,
}.get(indexType)
assert queryattr is not None, "Invalid type for record faulting query"
- # mailto: CUAs get normalized to lowercase internally, so do a case
- # insensitive search
- if queryattr == dsattributes.kDSNAttrEMailAddress:
- caseInsensitive = True
- else:
- caseInsensitive = False
+ # Make all OD queries case insensitive
+ caseInsensitive = True
results = []
for recordType in recordTypes:
Modified: CalendarServer/trunk/twistedcaldav/directory/cachingdirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/cachingdirectory.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/cachingdirectory.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -36,6 +36,7 @@
from twistedcaldav.config import config
from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord, DirectoryError, UnknownRecordTypeError
from twistedcaldav.scheduling.cuaddress import normalizeCUAddr
+from twistedcaldav.directory.util import normalizeUUID
class RecordTypeCache(object):
@@ -269,6 +270,7 @@
return self._lookupRecord(None, CachingDirectoryService.INDEX_TYPE_AUTHID, authID)
def recordWithGUID(self, guid):
+ guid = normalizeUUID(guid)
return self._lookupRecord(None, CachingDirectoryService.INDEX_TYPE_GUID, guid)
recordWithUID = recordWithGUID
Modified: CalendarServer/trunk/twistedcaldav/directory/directory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/directory.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/directory.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -48,7 +48,7 @@
from twistedcaldav.config import config
from twistedcaldav.directory.idirectory import IDirectoryService, IDirectoryRecord
-from twistedcaldav.directory.util import uuidFromName
+from twistedcaldav.directory.util import uuidFromName, normalizeUUID
from twistedcaldav.scheduling.cuaddress import normalizeCUAddr
from twistedcaldav import servers
from twistedcaldav.memcacher import Memcacher
@@ -176,12 +176,14 @@
return None
def recordWithUID(self, uid):
+ uid = normalizeUUID(uid)
for record in self.allRecords():
if record.uid == uid:
return record
return None
def recordWithGUID(self, guid):
+ guid = normalizeUUID(guid)
for record in self.allRecords():
if record.guid == guid:
return record
@@ -923,7 +925,7 @@
)
def __init__(
- self, service, recordType, guid,
+ self, service, recordType, guid=None,
shortNames=(), authIDs=set(), fullName=None,
firstName=None, lastName=None, emailAddresses=set(),
calendarUserAddresses=set(), autoSchedule=False, enabledForCalendaring=None,
@@ -937,8 +939,7 @@
assert recordType
assert shortNames and isinstance(shortNames, tuple)
- if not guid:
- guid = uuidFromName(service.guid, "%s:%s" % (recordType, ",".join(shortNames)))
+ guid = normalizeUUID(guid)
if uid is None:
uid = guid
@@ -978,12 +979,15 @@
"""
if not self.enabledForCalendaring:
return frozenset()
- return frozenset(
- ["urn:uuid:%s" % (self.guid,)] +
+ cuas = set(
["mailto:%s" % (emailAddress,)
for emailAddress in self.emailAddresses]
)
+ if self.guid:
+ cuas.add("urn:uuid:%s" % (self.guid,))
+ return frozenset(cuas)
+
calendarUserAddresses = property(get_calendarUserAddresses)
def __cmp__(self, other):
Modified: CalendarServer/trunk/twistedcaldav/directory/sudo.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/sudo.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/sudo.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -126,7 +126,7 @@
super(SudoDirectoryRecord, self).__init__(
service=service,
recordType=recordType,
- guid=None,
+ uid="%s:%s" % (recordType, shortName),
shortNames=(shortName,),
fullName=shortName,
)
Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_cachedirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_cachedirectory.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_cachedirectory.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -187,6 +187,9 @@
self.service.queried = False
self.assertTrue(self.service.recordWithGUID(self.guidForShortName("user01")) is not None)
self.assertFalse(self.service.queried)
+
+ # Make sure guid is case-insensitive
+ self.assertTrue(self.service.recordWithGUID(self.guidForShortName("user01").lower()) is not None)
def test_cacheoneshortname(self):
self.dummyRecords()
Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_directory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_directory.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_directory.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -25,6 +25,7 @@
from twistedcaldav.directory.xmlfile import XMLDirectoryService
from twistedcaldav.directory.calendaruserproxyloader import XMLCalendarUserProxyLoader
from twistedcaldav.directory import augment, calendaruserproxy
+from twistedcaldav.directory.util import normalizeUUID
from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
import cPickle as pickle
@@ -38,7 +39,7 @@
return 0
return 1
-class SALCTests(TestCase):
+class SACLTests(TestCase):
def setUp(self):
self.patch(DirectoryRecord, "CheckSACL", StubCheckSACL)
@@ -560,3 +561,47 @@
)
+class GUIDTests(TestCase):
+
+ def setUp(self):
+ self.service = DirectoryService()
+ self.service.setRealm("test")
+ self.service.baseGUID = "0E8E6EC2-8E52-4FF3-8F62-6F398B08A498"
+
+ def test_normalizeUUID(self):
+
+ # Ensure that record.guid automatically gets normalized to
+ # uppercase+hyphenated form if the value is one that uuid.UUID( )
+ # recognizes.
+
+ data = (
+ (
+ "0543A85A-D446-4CF6-80AE-6579FA60957F",
+ "0543A85A-D446-4CF6-80AE-6579FA60957F"
+ ),
+ (
+ "0543a85a-d446-4cf6-80ae-6579fa60957f",
+ "0543A85A-D446-4CF6-80AE-6579FA60957F"
+ ),
+ (
+ "0543A85AD4464CF680AE-6579FA60957F",
+ "0543A85A-D446-4CF6-80AE-6579FA60957F"
+ ),
+ (
+ "0543a85ad4464cf680ae6579fa60957f",
+ "0543A85A-D446-4CF6-80AE-6579FA60957F"
+ ),
+ (
+ "foo",
+ "foo"
+ ),
+ (
+ None,
+ None
+ ),
+ )
+ for original, expected in data:
+ self.assertEquals(expected, normalizeUUID(original))
+ record = DirectoryRecord(self.service, "users", original,
+ shortNames=("testing",))
+ self.assertEquals(expected, record.guid)
Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_util.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_util.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_util.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -24,5 +24,5 @@
def test_uuidFromName(self):
self.assertEquals(
uuidFromName(uuid_namespace_dns, "python.org"),
- "886313e1-3b8a-5372-9b90-0c9aee199e5d",
+ "886313E1-3B8A-5372-9B90-0C9AEE199E5D",
)
Modified: CalendarServer/trunk/twistedcaldav/directory/util.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/util.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/util.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -20,6 +20,7 @@
"""
__all__ = [
+ "normalizeUUID",
"uuidFromName",
]
@@ -38,8 +39,22 @@
if type(name) is unicode:
name = name.encode("utf-8")
- return str(uuid5(UUID(namespace), name))
+ return normalizeUUID(str(uuid5(UUID(namespace), name)))
+
+def normalizeUUID(value):
+ """
+ Convert strings which the uuid.UUID( ) method can parse into normalized
+ (uppercase with hyphens) form. Any value which is not parsed by UUID( )
+ is returned as is.
+ @param value: string value to normalize
+ """
+ try:
+ return str(UUID(value)).upper()
+ except (ValueError, TypeError):
+ return value
+
+
def transactionFromRequest(request, newStore):
"""
Return the associated transaction from the given HTTP request, creating a
Modified: CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -30,6 +30,7 @@
from twext.python.log import Logger
from twistedcaldav.directory.directory import DirectoryService
+from twistedcaldav.directory.util import normalizeUUID
import re
import hashlib
@@ -237,7 +238,7 @@
result = XMLAccountRecord(self.recordType)
result.shortNames = shortNames
- result.guid = guid
+ result.guid = normalizeUUID(guid)
result.password = password
result.fullName = fullName
result.firstName = firstName
Modified: CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlfile.py 2012-01-17 00:06:50 UTC (rev 8548)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlfile.py 2012-01-17 01:47:32 UTC (rev 8549)
@@ -34,6 +34,7 @@
from twistedcaldav.config import fullServerPath
from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord, DirectoryError
from twistedcaldav.directory.xmlaccountsparser import XMLAccountsParser, XMLAccountRecord
+from twistedcaldav.directory.util import normalizeUUID
from twistedcaldav.scheduling.cuaddress import normalizeCUAddr
from twistedcaldav.xmlutil import addSubElement, createElement, elementToXML
from uuid import uuid4
@@ -256,6 +257,7 @@
return None
def recordWithGUID(self, guid):
+ guid = normalizeUUID(guid)
for recordType in self.recordTypes():
record = self._lookupInIndex(recordType, self.INDEX_TYPE_GUID, guid)
if record is not None:
@@ -431,6 +433,7 @@
"""
if guid is None:
guid = str(uuid4())
+ guid = normalizeUUID(guid)
if not shortNames:
shortNames = (guid,)
@@ -473,6 +476,8 @@
disk.
"""
+ guid = normalizeUUID(guid)
+
# Make sure latest XML records are read in
accounts = self._forceReload()
@@ -497,6 +502,8 @@
is serialized to disk.
"""
+ guid = normalizeUUID(guid)
+
# Make sure latest XML records are read in
accounts = self._forceReload()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120116/3f0aa2d6/attachment-0001.html>
More information about the calendarserver-changes
mailing list