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

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:23:13 PDT 2014


Revision: 12747
          http://trac.calendarserver.org//changeset/12747
Author:   wsanchez at apple.com
Date:     2014-02-24 18:26:17 -0800 (Mon, 24 Feb 2014)
Log Message:
-----------
ConstantsContainer.__init__() no longer raises if it sees the same name twice, as long as the same constant is associated with the name.

Modified Paths:
--------------
    twext/trunk/twext/who/test/test_util.py
    twext/trunk/twext/who/util.py

Modified: twext/trunk/twext/who/test/test_util.py
===================================================================
--- twext/trunk/twext/who/test/test_util.py	2014-02-25 02:15:35 UTC (rev 12746)
+++ twext/trunk/twext/who/test/test_util.py	2014-02-25 02:26:17 UTC (rev 12747)
@@ -155,13 +155,20 @@
         self.assertRaises(TypeError, ConstantsContainer, (Tools, Switches))
 
 
-    def test_conflictingNames(self):
+    def test_conflictingNames_different(self):
         """
-        A container can't contain two constants with the same name.
+        A container can't contain two different constants with the same name.
         """
         self.assertRaises(ValueError, ConstantsContainer, (Tools, Instruments))
 
 
+    def test_conflictingNames_same(self):
+        """
+        A container can combine containers which contain the same constants.
+        """
+        ConstantsContainer((Tools, Tools))
+
+
     def test_notConstantClass(self):
         """
         A container can't contain random classes.

Modified: twext/trunk/twext/who/util.py
===================================================================
--- twext/trunk/twext/who/util.py	2014-02-25 02:15:35 UTC (rev 12746)
+++ twext/trunk/twext/who/util.py	2014-02-25 02:26:17 UTC (rev 12747)
@@ -79,21 +79,27 @@
                 if issubclass(self._constantsClass, ValueConstant):
                     self.lookupByValue = self._lookupByValue
 
-            if constant.name in self._constants:
+            if (
+                constant.name in self._constants and
+                self._constants[constant.name] is not constant
+            ):
                 raise ValueError("Name conflict: {0}".format(constant.name))
 
             self._constants[constant.name] = constant
 
 
     def _addMethods(self, methods):
-        for name, value in methods:
+        for name, method in methods:
             if name[0] == "_":
                 continue
 
-            if name in self._constants or name in self._methods:
+            if (
+                name in self._constants or
+                (name in self._methods and self._methods[name] is not method)
+            ):
                 raise ValueError("Name conflict: {0}".format(name))
 
-            self._methods[name] = value
+            self._methods[name] = method
 
 
     def __getattr__(self, name):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/1d38b86e/attachment.html>


More information about the calendarserver-changes mailing list