[Checkins] SVN: zope.introspector/trunk/src/zope/introspector/code.py Add methods to determine parents of code objects.

Uli Fouquet uli at gnufix.de
Sun Aug 10 09:38:51 EDT 2008


Log message for revision 89596:
  Add methods to determine parents of code objects.

Changed:
  U   zope.introspector/trunk/src/zope/introspector/code.py

-=-
Modified: zope.introspector/trunk/src/zope/introspector/code.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/code.py	2008-08-10 10:16:05 UTC (rev 89595)
+++ zope.introspector/trunk/src/zope/introspector/code.py	2008-08-10 13:38:50 UTC (rev 89596)
@@ -33,6 +33,14 @@
     def __init__(self, dotted_name):
         self.dotted_name = dotted_name
 
+    def getParents(self):
+        dotted_name = self.dotted_name
+        parts = dotted_name.split('.')
+        result = [Package(parts[0]),]
+        for part in parts[1:]:
+            result.append(result[-1][part])
+        return tuple(result)
+
 class PackageOrModule(Code):
     def __init__(self, dotted_name):
         super(PackageOrModule, self).__init__(dotted_name)
@@ -137,6 +145,14 @@
         super(File, self).__init__(dotted_name)
         self.name = name
 
+    def getParents(self):
+        """Get the parents tuple with the filename appended.
+        """
+        # Files don't store their own name in the dotted_name.
+        result = list(super(File, self).getParents())
+        result.append(self)
+        return tuple(result)
+
     def exists(self):
         """Check whether the file is a file we want to consider."""
         module_info = module_info_from_dotted_name(self.dotted_name)



More information about the Checkins mailing list