[CalendarServer-changes] [12583] twext/trunk/twext/who

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:22:20 PDT 2014


Revision: 12583
          http://trac.calendarserver.org//changeset/12583
Author:   wsanchez at apple.com
Date:     2014-02-05 16:45:30 -0800 (Wed, 05 Feb 2014)
Log Message:
-----------
.valueType on a field now expects a container for constants.

Modified Paths:
--------------
    twext/trunk/twext/who/directory.py
    twext/trunk/twext/who/idirectory.py
    twext/trunk/twext/who/xml.py

Modified: twext/trunk/twext/who/directory.py
===================================================================
--- twext/trunk/twext/who/directory.py	2014-02-06 00:17:39 UTC (rev 12582)
+++ twext/trunk/twext/who/directory.py	2014-02-06 00:45:30 UTC (rev 12583)
@@ -26,6 +26,11 @@
 
 from zope.interface import implementer, directlyProvides
 
+from twisted.python.constants import (
+    Names, NamedConstant,
+    Values, ValueConstant,
+    Flags, FlagConstant,
+)
 from twisted.internet.defer import inlineCallbacks, returnValue
 from twisted.internet.defer import succeed, fail
 from twisted.cred.credentials import DigestedCredentials
@@ -352,6 +357,14 @@
 
         def checkType(name, value):
             expectedType = service.fieldName.valueType(name)
+
+            if issubclass(expectedType, Names):
+                expectedType = NamedConstant
+            elif issubclass(expectedType, Values):
+                expectedType = ValueConstant
+            elif issubclass(expectedType, Flags):
+                expectedType = FlagConstant
+
             if not isinstance(value, expectedType):
                 raise InvalidDirectoryRecordError(
                     "Value {0!r} for field {1} is not of type {2}".format(

Modified: twext/trunk/twext/who/idirectory.py
===================================================================
--- twext/trunk/twext/who/idirectory.py	2014-02-06 00:17:39 UTC (rev 12582)
+++ twext/trunk/twext/who/idirectory.py	2014-02-06 00:45:30 UTC (rev 12583)
@@ -146,8 +146,17 @@
     """
     Constants for common directory record field names.
 
-    Fields as associated with either a single value or an iterable of values.
+    Fields as associated with either a single value (the default) or an
+    iterable of values (if it has a true C{multiValue} attribute).
 
+    Field values must be an instance of an expected type.  The default expected
+    type for a field is L{unicode}, and may be overriden by a C{valueType}
+    attribute on the field name.
+
+    In the case where the expected type is a constant (eg. L{NamedConstant}),
+    C{valueType} should be the container that contains the constant (eg. a
+    subclass of L{Names}).
+
     @cvar uid: The primary unique identifier for a directory record.
         The associated value must be a L{unicode}.
 

Modified: twext/trunk/twext/who/xml.py
===================================================================
--- twext/trunk/twext/who/xml.py	2014-02-06 00:17:39 UTC (rev 12582)
+++ twext/trunk/twext/who/xml.py	2014-02-06 00:45:30 UTC (rev 12583)
@@ -35,7 +35,7 @@
     tostring as etreeToString, Element as XMLElement,
 )
 
-from twisted.python.constants import NamedConstant, Values, ValueConstant
+from twisted.python.constants import Names, Values, ValueConstant, Flags
 from twisted.internet.defer import fail
 
 from .idirectory import (
@@ -354,7 +354,7 @@
                         .format(boolElement.value, fieldNode.tag)
                     )
 
-            elif valueType is NamedConstant:
+            elif issubclass(valueType, (Names, Values, Flags)):
                 constantElement = self._constantElement(fieldNode)
 
                 value = constantElement.constantValue
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/6e268c68/attachment.html>


More information about the calendarserver-changes mailing list