[CalendarServer-changes] [10707] CalendarServer/trunk/twext/who
source_changes at macosforge.org
source_changes at macosforge.org
Tue Feb 12 15:00:12 PST 2013
Revision: 10707
http://trac.calendarserver.org//changeset/10707
Author: wsanchez at apple.com
Date: 2013-02-12 15:00:12 -0800 (Tue, 12 Feb 2013)
Log Message:
-----------
Add field normalization
Modified Paths:
--------------
CalendarServer/trunk/twext/who/directory.py
CalendarServer/trunk/twext/who/idirectory.py
CalendarServer/trunk/twext/who/test/test_directory.py
Modified: CalendarServer/trunk/twext/who/directory.py
===================================================================
--- CalendarServer/trunk/twext/who/directory.py 2013-02-12 22:16:23 UTC (rev 10706)
+++ CalendarServer/trunk/twext/who/directory.py 2013-02-12 23:00:12 UTC (rev 10707)
@@ -164,8 +164,22 @@
fields[FieldName.recordType]
))
+ # Normalize fields
+ normalizedFields = {}
+ for name, value in fields.items():
+ normalize = getattr(name, "normalize", None)
+
+ if normalize is None:
+ normalizedFields[name] = value
+ continue
+
+ if FieldName.isMultiValue(name):
+ normalizedFields[name] = tuple((normalize(v) for v in value))
+ else:
+ normalizedFields[name] = normalize(value)
+
self.service = service
- self.fields = fields
+ self.fields = normalizedFields
def __repr__(self):
Modified: CalendarServer/trunk/twext/who/idirectory.py
===================================================================
--- CalendarServer/trunk/twext/who/idirectory.py 2013-02-12 22:16:23 UTC (rev 10706)
+++ CalendarServer/trunk/twext/who/idirectory.py 2013-02-12 23:00:12 UTC (rev 10707)
@@ -37,6 +37,8 @@
"IDirectoryRecord",
]
+from uuid import UUID
+
from zope.interface import Attribute, Interface
from twisted.python.constants import Names, NamedConstant
@@ -124,8 +126,11 @@
def isMultiValue(name):
return getattr(name, "multiValue", False)
+ guid.normalize = lambda g: UUID(g).hex
+ emailAddresses.normalize = lambda e: e.lower()
+
class MatchType(Names):
"""
Query match types.
Modified: CalendarServer/trunk/twext/who/test/test_directory.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_directory.py 2013-02-12 22:16:23 UTC (rev 10706)
+++ CalendarServer/trunk/twext/who/test/test_directory.py 2013-02-12 23:00:12 UTC (rev 10707)
@@ -102,7 +102,7 @@
class DirectoryRecordTest(BaseTest):
fields_wsanchez = {
- FieldName.uid: "wsanchez",
+ FieldName.uid: "UID:wsanchez",
FieldName.recordType: RecordType.user,
FieldName.shortNames: ("wsanchez", "wilfredo_sanchez"),
FieldName.fullNames: ("Wilfredo Sanchez", "Wilfredo Sanchez Vega"),
@@ -110,14 +110,22 @@
}
fields_glyph = {
- FieldName.uid: "glyph",
+ FieldName.uid: "UID:glyph",
FieldName.recordType: RecordType.user,
FieldName.shortNames: ("glyph",),
FieldName.fullNames: ("Glyph Lefkowitz",),
FieldName.emailAddresses: ("glyph at calendarserver.org",)
}
+ fields_sagen = {
+ FieldName.uid: "UID:sagen",
+ FieldName.recordType: RecordType.user,
+ FieldName.shortNames: ("sagen",),
+ FieldName.fullNames: ("Morgen Sagen",),
+ FieldName.emailAddresses: ("sagen at CalendarServer.org",)
+ }
+
def _testRecord(self, fields=None, service=None):
if fields is None:
fields = self.fields_wsanchez
@@ -136,7 +144,7 @@
def test_init(self):
service = self._testService()
- wsanchez = self._testRecord(self.fields_wsanchez)
+ wsanchez = self._testRecord(self.fields_wsanchez, service=service)
self.assertEquals(wsanchez.service, service)
self.assertEquals(wsanchez.fields , self.fields_wsanchez)
@@ -186,6 +194,15 @@
self.assertRaises(ValueError, self._testRecord, fields)
+ def test_initNormalize(self):
+ sagen = self._testRecord(self.fields_sagen)
+
+ self.assertEquals(
+ sagen.fields[FieldName.emailAddresses],
+ ("sagen at calendarserver.org",)
+ )
+
+
def test_compare(self):
fields_glyphmod = self.fields_glyph.copy()
del fields_glyphmod[FieldName.emailAddresses]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130212/2b018daa/attachment.html>
More information about the calendarserver-changes
mailing list