[CalendarServer-changes] [12498] twext/trunk/twext/who/util.py

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


Revision: 12498
          http://trac.calendarserver.org//changeset/12498
Author:   wsanchez at apple.com
Date:     2014-01-30 18:00:15 -0800 (Thu, 30 Jan 2014)
Log Message:
-----------
Handle methods from a ConstantsContainer.

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

Modified: twext/trunk/twext/who/util.py
===================================================================
--- twext/trunk/twext/who/util.py	2014-01-31 01:27:29 UTC (rev 12497)
+++ twext/trunk/twext/who/util.py	2014-01-31 02:00:15 UTC (rev 12498)
@@ -26,7 +26,7 @@
     "iterFlags",
 ]
 
-from inspect import isclass
+from inspect import getmembers, isclass, isfunction
 
 from twisted.python.constants import (
     Names, Values, Flags, NamedConstant, ValueConstant, FlagConstant,
@@ -48,7 +48,7 @@
             if isclass(source):
                 if issubclass(source, CONTAINER_CLASSES):
                     self._addConstants(source.iterconstants())
-                    self._addMethods(source)
+                    self._addMethods(getmembers(source, isfunction))
                 else:
                     raise TypeError(
                         "Unknown constants type: {0}".format(source)
@@ -56,7 +56,7 @@
 
             elif isinstance(source, ConstantsContainer):
                 self._addConstants(source.iterconstants())
-                self._addMethods(source)
+                self._addMethods(source._methods.iteritems())
 
             elif isinstance(source, CONSTANT_CLASSES):
                 self._addConstants((source,))
@@ -86,15 +86,17 @@
             self._constants[constant.name] = constant
 
 
-    def _addMethods(self, container):
-        for name, value in container.__dict__.iteritems():
-            if type(value) is staticmethod:
-                if name in self._constants or name in self._methods:
-                    raise ValueError("Name conflict: {0}".format(name))
+    def _addMethods(self, methods):
+        for name, value in methods:
+            if name[0] == "_":
+                continue
 
-                self._methods[name] = getattr(container, name)
+            if name in self._constants or name in self._methods:
+                raise ValueError("Name conflict: {0}".format(name))
 
+            self._methods[name] = value
 
+
     def __getattr__(self, name):
         attr = self._constants.get(name, None)
         if attr is not None:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/b9ecafce/attachment.html>


More information about the calendarserver-changes mailing list