[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Introspector - IIntrospector.py:1.2.12.1 Introspector.py:1.2.12.1

Deb dhazarika@zeomega.com
Fri, 25 Oct 2002 06:32:51 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Introspector
In directory cvs.zope.org:/tmp/cvs-serv1557/lib/python/Zope/App/OFS/Introspector

Modified Files:
      Tag: Zope3-Bangalore-TTW-Branch
	IIntrospector.py Introspector.py 
Log Message:
Introspector updated and is functional in ZMI


=== Zope3/lib/python/Zope/App/OFS/Introspector/IIntrospector.py 1.2 => 1.2.12.1 ===
--- Zope3/lib/python/Zope/App/OFS/Introspector/IIntrospector.py:1.2	Mon Jun 10 19:28:07 2002
+++ Zope3/lib/python/Zope/App/OFS/Introspector/IIntrospector.py	Fri Oct 25 06:32:50 2002
@@ -15,16 +15,37 @@
 
 class IIntrospector(Interface):
     """An interface for introspecting a component"""
-    
-    def getName():
-        """Returns the component name"""
+
+    def isInterface():
+        "Checks if the context is class or interface"
+        
+    def setRequest(request):
+        """sets the request"""
+        
+    def getClass():
+        """Returns the class name"""
+
+    def getBaseClassNames():
+        """Returns the names of the classes"""
+        
+    def getModule():
+        """Returns the module name of the class"""
     
     def getDocString():
-        """Returns the description of component (string)"""
+        """Returns the description of the class"""
         
     def getInterfaces():
-        """Returns interfaces implemented by this component (iterator)"""
+        """Returns interfaces implemented by this class"""
+
+    def getInterfaceNames():
+        """Returns the name of the interface"""
         
-    def getInterfaceNames():
-        """Returns dotted names usable by the interface reference"""
+    def getInterfaceDetails():
+        """Returns the entire documentation in the interface"""
+
+    def getExtends():
+        """Returns all the class extended up to the top most level"""
+
+    def getInterfaceConfiguration():
+        """Returns details for a interface configuration"""        
 


=== Zope3/lib/python/Zope/App/OFS/Introspector/Introspector.py 1.2 => 1.2.12.1 ===
--- Zope3/lib/python/Zope/App/OFS/Introspector/Introspector.py:1.2	Mon Jun 10 19:28:07 2002
+++ Zope3/lib/python/Zope/App/OFS/Introspector/Introspector.py	Fri Oct 25 06:32:50 2002
@@ -14,39 +14,122 @@
 from Interface import Interface
 from Interface.Implements import implements, getImplements
 from IIntrospector import IIntrospector
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
+from Zope.ComponentArchitecture import getServiceManager, getAdapter, queryServiceManager, getServiceDefinitions
+from Zope.App.OFS.Services.ServiceManager.INameResolver import INameResolver
+import string
 
+
 class Introspector:
-    def __init__(self, component):
-        self._component=component.__class__
-        
-    def getName(self):
-        return self._component.__name__
-        
-    def getDocString(self):
-        return self._component.__doc__
+    """Introspecs an object"""
+    __implements__ = IIntrospector
     
-    def getInterfaces(self):
-        imple=self._component.__implements__
-        if type(imple) != tuple:
-            imple=(imple,)
-        else:
-            imple=self._unpackTuple(imple)
-        return imple
+
+    def __init__(self, context):
+        self.context = context
+        self.request = None
+        self.currentclass = None
+        
+    def isInterface(self):
+        "Checks if the context is class or interface"
+        return int(Interface.isImplementedBy(self.context))
     
-    def getInterfaceNames(self):
-        names=[]
-        for intObj in self.getInterfaces():
-            names.append(intObj.__module__ + '.' + intObj.__name__)
-        names.sort()
-        return names
-        
-    def _unpackTuple(self, imple):
+    def setRequest(self, request):
+        """sets the request"""
+        self.request = request
+        path = self.request['PATH_INFO']
+        name = path[string.rfind(path, '++module++')+len('++module++'):]
+        if string.find(path, '++module++') != -1:
+            if self.context == Interface and name != 'Interface._Interface.Interface':
+                servicemanager = getServiceManager(self.context)
+                adapter = getAdapter(servicemanager, INameResolver)
+                self.currentclass = adapter.resolve(name)
+                self.context = self.currentclass
+            else:
+                self.currentclass = self.context
+        else:
+            self.currentclass = self.context.__class__
+            
+
+    def _unpackTuple(self, tuple_obj):
         res=[]
-        for imp in imple:
-            if type(imp)==tuple:
-                res.extend(self._unpackTuple(imp))
-            else: res.append(imp)
+        for item in tuple_obj:
+            if type(item)==tuple:
+                res.extend(self._unpackTuple(item))
+            else: res.append(item)
         return tuple(res)
     
+    def getClass(self):
+        """Returns the class name"""
+        return (self.currentclass).__name__
+
+    def getBaseClassNames(self):
+        """Returns the names of the classes"""
+        bases = self.getExtends()
+        base_names = []
+        for base in bases:
+            base_names.append(base.__module__+'.'+base.__name__)
+        return base_names
+    
+    def getModule(self):
+        """Returns the module name of the class"""
+        return (self.currentclass).__module__
+       
+    def getDocString(self):
+        """Returns the description of the class"""
+        return removeAllProxies(self.currentclass).__doc__
+        
+    def getInterfaces(self):
+        """Returns interfaces implemented by this class"""
+        interfaces = removeAllProxies(self.currentclass).__implements__
+        if type(interfaces) != tuple:
+            interfaces = (interfaces,)
+        else:
+            interfaces = self._unpackTuple(interfaces)
+        return interfaces
+
+    def getInterfaceNames(self):
+        names=[]
+        try:
+            for intObj in self.getInterfaces():
+                names.append(intObj.__module__ + '.' + intObj.__name__)
+            names.sort()
+            return names
+        except:
+            return []
     
-implements(Introspector, IIntrospector)
\ No newline at end of file
+        
+    def getInterfaceDetails(self):
+        """Returns the entire documentation in the interface"""
+        interface = self.context
+        Iname, bases, desc, methods, attributes = interface.__name__, [], '', [], []
+        if interface is not None:
+            namesAndDescriptions = interface.namesAndDescriptions()
+            namesAndDescriptions.sort()
+            for name, desc in namesAndDescriptions:
+                if hasattr(desc, 'getSignatureString'):
+                    methods.append((desc.getName(), desc.getSignatureString(), desc.getDoc()))
+                else:
+                    attributes.append((desc.getName(), desc.getDoc()))
+                
+            for base in interface.getBases():
+                bases.append(base.__module__+'.'+base.__name__)
+            desc = str(interface.__doc__)
+        return [Iname, bases, desc, methods, attributes]
+            
+
+    def getExtends(self):
+        """Returns all the class extended up to the top most level"""
+        bases = self._unpackTuple((self.currentclass).__bases__)
+        return bases
+
+    def getInterfaceConfiguration(self):
+        """Returns details for a interface configuration"""
+        #sm = queryServiceManager(self.context)
+        service = []
+        for name, interface in getServiceDefinitions(self.context):
+            if self.context.extends(interface):
+                service.append(str(name))
+        print service
+        return service
+