[CalendarServer-changes] [12389] twext/trunk/twext
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:18:07 PDT 2014
Revision: 12389
http://trac.calendarserver.org//changeset/12389
Author: wsanchez at apple.com
Date: 2014-01-17 15:28:30 -0800 (Fri, 17 Jan 2014)
Log Message:
-----------
Add MappingProxyType.
Modified Paths:
--------------
twext/trunk/twext/who/ldap/_service.py
Added Paths:
-----------
twext/trunk/twext/python/types.py
Added: twext/trunk/twext/python/types.py
===================================================================
--- twext/trunk/twext/python/types.py (rev 0)
+++ twext/trunk/twext/python/types.py 2014-01-17 23:28:30 UTC (rev 12389)
@@ -0,0 +1,110 @@
+##
+# Copyright (c) 2011-2014 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.
+##
+
+"""
+Utilities related to types.
+"""
+
+__all__ = [
+ "MappingProxyType",
+]
+
+
+
+class MappingProxyType(object):
+ """
+ Read-only proxy of a mapping. It provides a dynamic view on the mapping's
+ entries, which means that when the mapping changes, the view reflects these
+ changes.
+
+ Backport of Python 3's L{types.MappingProxyType
+ <http://docs.python.org/dev/library/types.html#types.MappingProxyType>}.
+ """
+
+ def __init__(self, mapping):
+ """
+ @param mapping: A mapping to wrap.
+ @type mapping: mapping
+ """
+ self._mapping = mapping
+
+
+ def __len__(self):
+ return len(self._mapping)
+
+
+ def __getitem__(self, key):
+ return self._mapping[key]
+
+
+ def __iter__(self):
+ return iter(self._mapping)
+
+
+ def __reversed__(self):
+ return reversed(self._mapping)
+
+
+ def __contains__(self, key):
+ return key in self._mapping
+
+
+ def copy(self):
+ return self._mapping.copy()
+
+
+ def get(self, key, default=None):
+ return self._mapping.get(key, default)
+
+
+ def has_key(self, key):
+ return key in self._mapping
+
+
+ def items(self):
+ return self._mapping.items()
+
+
+ def iteritems(self):
+ return self._mapping.iteritems()
+
+
+ def iterkeys(self):
+ return self._mapping.iterkeys()
+
+
+ def itervalues(self):
+ return self._mapping.itervalues()
+
+
+ def keys(self):
+ return self._mapping.keys()
+
+
+ def values(self):
+ return self._mapping.values()
+
+
+ def viewitems(self):
+ return self._mapping.viewitems()
+
+
+ def viewkeys(self):
+ return self._mapping.viewkeys()
+
+
+ def viewvalues(self):
+ return self._mapping.viewvalues()
Modified: twext/trunk/twext/who/ldap/_service.py
===================================================================
--- twext/trunk/twext/who/ldap/_service.py 2014-01-17 23:28:18 UTC (rev 12388)
+++ twext/trunk/twext/who/ldap/_service.py 2014-01-17 23:28:30 UTC (rev 12389)
@@ -30,6 +30,7 @@
from twisted.cred.credentials import IUsernamePassword
from twext.python.log import Logger
+from twext.python.types import MappingProxyType
from ..idirectory import (
DirectoryServiceError, DirectoryAvailabilityError,
@@ -50,21 +51,21 @@
# Maps field name -> LDAP attribute names
-DEFAULT_FIELDNAME_ATTRIBUTE_MAP = {
+DEFAULT_FIELDNAME_ATTRIBUTE_MAP = MappingProxyType({
BaseFieldName.guid: (LDAPAttribute.generatedUUID.value,),
BaseFieldName.recordType: (LDAPAttribute.objectClass.value,),
BaseFieldName.shortNames: (LDAPAttribute.uid.value,),
BaseFieldName.fullNames: (LDAPAttribute.cn.value,),
BaseFieldName.emailAddresses: (LDAPAttribute.mail.value,),
BaseFieldName.password: (LDAPAttribute.userPassword.value,),
-}
+})
# Maps record type -> LDAP object class names
-DEFAULT_RECORDTYPE_OBJECTCLASS_MAP = {
+DEFAULT_RECORDTYPE_OBJECTCLASS_MAP = MappingProxyType({
BaseRecordType.user: (LDAPObjectClass.inetOrgPerson.value,),
BaseRecordType.group: (LDAPObjectClass.groupOfNames.value,),
-}
+})
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/31332fe7/attachment.html>
More information about the calendarserver-changes
mailing list