[CalendarServer-changes] [10659] CalendarServer/trunk/twext/who
source_changes at macosforge.org
source_changes at macosforge.org
Thu Feb 7 16:52:10 PST 2013
Revision: 10659
http://trac.calendarserver.org//changeset/10659
Author: wsanchez at apple.com
Date: 2013-02-07 16:52:10 -0800 (Thu, 07 Feb 2013)
Log Message:
-----------
Move utilities into a util module.
Modified Paths:
--------------
CalendarServer/trunk/twext/who/directory.py
CalendarServer/trunk/twext/who/xml.py
Added Paths:
-----------
CalendarServer/trunk/twext/who/util.py
Modified: CalendarServer/trunk/twext/who/directory.py
===================================================================
--- CalendarServer/trunk/twext/who/directory.py 2013-02-08 00:50:54 UTC (rev 10658)
+++ CalendarServer/trunk/twext/who/directory.py 2013-02-08 00:52:10 UTC (rev 10659)
@@ -23,58 +23,21 @@
"DirectoryRecord",
]
-from types import FunctionType
-
from zope.interface import implements
from twisted.python.util import FancyEqMixin
-from twisted.python.constants import NamedConstant
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.defer import succeed, fail
-from twext.who.idirectory import DirectoryServiceError
from twext.who.idirectory import QueryNotSupportedError
from twext.who.idirectory import FieldName, RecordType
from twext.who.idirectory import Operand
from twext.who.idirectory import DirectoryQueryMatchExpression
from twext.who.idirectory import IDirectoryService, IDirectoryRecord
+from twext.who.util import MergedConstants, uniqueResult
-class MergedConstants(object):
- """
- Work-around for the fact that Names is apparently not subclassable
- and doesn't provide a way to merge multiple Names classes.
- """
- def __init__(self, *containers):
- self._containers = containers
-
- def __getattr__(self, name):
- for container in self._containers:
- attr = getattr(container, name, None)
- if attr is not None:
- # Named constant or static method
- if isinstance(attr, (NamedConstant, FunctionType)):
- return attr
-
- raise AttributeError(name)
-
- def iterconstants(self):
- for container in self._containers:
- for constant in container.iterconstants():
- yield constant
-
- def lookupByName(self, name):
- for container in self._containers:
- try:
- return container.lookupByName(name)
- except ValueError:
- pass
-
- raise ValueError(name)
-
-
-
class DirectoryService(FancyEqMixin, object):
implements(IDirectoryService)
@@ -229,16 +192,6 @@
raise NotImplementedError()
return succeed(())
+
def groups(self):
raise NotImplementedError()
-
-
-
-def uniqueResult(values):
- result = None
- for value in values:
- if result is None:
- result = value
- else:
- raise DirectoryServiceError("Multiple values found where one expected.")
- return result
Added: CalendarServer/trunk/twext/who/util.py
===================================================================
--- CalendarServer/trunk/twext/who/util.py (rev 0)
+++ CalendarServer/trunk/twext/who/util.py 2013-02-08 00:52:10 UTC (rev 10659)
@@ -0,0 +1,74 @@
+##
+# Copyright (c) 2013 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Directory service module utilities.
+"""
+
+__all__ = [
+ "MergedConstants",
+]
+
+from types import FunctionType
+
+from twisted.python.constants import NamedConstant
+
+from twext.who.idirectory import DirectoryServiceError
+
+
+
+class MergedConstants(object):
+ """
+ Work-around for the fact that Names is apparently not subclassable
+ and doesn't provide a way to merge multiple Names classes.
+ """
+ def __init__(self, *containers):
+ self._containers = containers
+
+ def __getattr__(self, name):
+ for container in self._containers:
+ attr = getattr(container, name, None)
+ if attr is not None:
+ # Named constant or static method
+ if isinstance(attr, (NamedConstant, FunctionType)):
+ return attr
+
+ raise AttributeError(name)
+
+ def iterconstants(self):
+ for container in self._containers:
+ for constant in container.iterconstants():
+ yield constant
+
+ def lookupByName(self, name):
+ for container in self._containers:
+ try:
+ return container.lookupByName(name)
+ except ValueError:
+ pass
+
+ raise ValueError(name)
+
+
+
+def uniqueResult(values):
+ result = None
+ for value in values:
+ if result is None:
+ result = value
+ else:
+ raise DirectoryServiceError("Multiple values found where one expected.")
+ return result
Modified: CalendarServer/trunk/twext/who/xml.py
===================================================================
--- CalendarServer/trunk/twext/who/xml.py 2013-02-08 00:50:54 UTC (rev 10658)
+++ CalendarServer/trunk/twext/who/xml.py 2013-02-08 00:52:10 UTC (rev 10659)
@@ -348,5 +348,6 @@
members.add((yield self.service.recordWithUID(uid)))
returnValue(members)
+
def groups(self):
return self.service.recordsWithFieldValue(FieldName.memberUIDs, self.uid)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130207/f85ea997/attachment-0001.html>
More information about the calendarserver-changes
mailing list