[Checkins] SVN: zope.introspector/trunk/src/zope/introspector/ More methods on the object info.

Lennart Regebro regebro at gmail.com
Mon Jul 21 13:36:09 EDT 2008


Log message for revision 88654:
  More methods on the object info.
  

Changed:
  U   zope.introspector/trunk/src/zope/introspector/interfaces.py
  U   zope.introspector/trunk/src/zope/introspector/objectinfo.py

-=-
Modified: zope.introspector/trunk/src/zope/introspector/interfaces.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/interfaces.py	2008-07-21 16:09:37 UTC (rev 88653)
+++ zope.introspector/trunk/src/zope/introspector/interfaces.py	2008-07-21 17:36:08 UTC (rev 88654)
@@ -49,6 +49,30 @@
         """Returnes wether or not this is a Class.
         """    
 
+    def isModule(self):
+        """Returns true of the object is a module.
+        """
+
+    def isClass(self):
+        """Returns true of the object is a class.
+        """
+        
+    def getDottedName(self):
+        """Returns the dotted name of the object.
+        """
+    
+    def getFile(self):
+        """Returns the source file where the object is defined.
+        """
+        
+    def getAttributes(self):
+        """Return all attributes of the object.
+        """
+            
+    def getMethods(self):
+        """Returns all methods of the object.
+        """
+        
 class IModuleInfo(interface.Interface):
     """Information about modules.
     """

Modified: zope.introspector/trunk/src/zope/introspector/objectinfo.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/objectinfo.py	2008-07-21 16:09:37 UTC (rev 88653)
+++ zope.introspector/trunk/src/zope/introspector/objectinfo.py	2008-07-21 17:36:08 UTC (rev 88654)
@@ -27,9 +27,8 @@
 
     dotted_name = None
     
-    def __init__(self, obj, dotted_name=None):
+    def __init__(self, obj):
         self.obj = obj
-        self.dotted_name = dotted_name
         
     def getType(self):
         return type(self.obj)
@@ -39,6 +38,38 @@
 
     def isClass(self):
         return inspect.isclass(self.obj)
+    
+    def getDottedName(self):
+        if self.isClass():
+            class_ = self.obj
+        else:
+            class_ = self.obj.__class__
+            
+        return class_.__module__ + '.' + class_.__name__
+    
+    def getFile(self):
+        try:
+            return inspect.getsourcefile(self.obj)
+        except TypeError:
+            return inspect.getsourcefile(self.getType())
+        
+    def getAttributes(self):
+        attributes = []
+        for id, value in inspect.getmembers(self.obj):
+            if inspect.ismethod(value):
+                continue
+            attributes.append({'id': id,
+                               'value': value,
+                               })
+        return attributes
+            
+    def getMethods(self):
+        methods = []
+        for id, value in inspect.getmembers(self.obj):
+            if inspect.ismethod(value):
+                methods.append({'id': id,
+                                })
+        return methods
 
 class ModuleInfo(ObjectInfo):
     grok.implements(IModuleInfo)



More information about the Checkins mailing list