[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Introspector - IIntrospector.py:1.3 Introspector.py:1.3 configure.zcml:1.4

Gary Poster gary@zope.com
Thu, 19 Dec 2002 13:26:04 -0500


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

Modified Files:
	IIntrospector.py Introspector.py configure.zcml 
Log Message:
Cleaned up merge of Introspector work in Bangalore branch.  will not be hooked up until the OFS configure.zcml is also committed: I'm going to test my commit before I do so.

When this is hooked up, it will add an Introspector action in the UI.

This html was broken in the Rotterdam skin; fixed and significantly cleaned up.

A lot of DOS line endings were removed.  dos2unix reports that all is well now.

Commented-out code in the view refers to an IConfigureFor interface that goes in a direction that Jim eventually wants.  I am not merging in the necessary code elsewhere (in the services) that this code needs, so therefore I comment it out but do not delete it.

Introspector tab will be available to anonymous user, as it was in the branch.  If we don't like this, we can just fix the zcml.




=== Zope3/lib/python/Zope/App/OFS/Introspector/IIntrospector.py 1.2 => 1.3 ===
--- 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	Thu Dec 19 13:25:32 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 dotted names usable by the interface reference"""
+        """Returns the name of the interface"""
+        
+    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.3 ===
--- 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	Thu Dec 19 13:25:32 2002
@@ -11,42 +11,141 @@
 # FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
-from Interface import Interface
+from Interface import Interface, IInterface
 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__
+    """Introspecs an object"""
+    __implements__ = IIntrospector
+    
+
+    def __init__(self, context):
+        self.context = context
+        self.request = None
+        self.currentclass = None
         
-    def getDocString(self):
-        return self._component.__doc__
+    def isInterface(self):
+        "Checks if the context is class or interface"
+        try:
+            ck = self.context.namesAndDescriptions()
+            return 1
+        except:
+            return 0
     
-    def getInterfaces(self):
-        imple=self._component.__implements__
-        if type(imple) != tuple:
-            imple=(imple,)
+    def setRequest(self, request):
+        """sets the request"""
+        self.request = request
+        if 'PATH_INFO' in request:
+            path = self.request['PATH_INFO']
         else:
-            imple=self._unpackTuple(imple)
-        return imple
-    
-    def getInterfaceNames(self):
-        names=[]
-        for intObj in self.getInterfaces():
-            names.append(intObj.__module__ + '.' + intObj.__name__)
-        names.sort()
-        return names
-        
-    def _unpackTuple(self, imple):
-        res=[]
-        for imp in imple:
-            if type(imp)==tuple:
-                res.extend(self._unpackTuple(imp))
-            else: res.append(imp)
+            path = ''
+        name = path[string.rfind(path, '++module++')+len('++module++'):]
+        name = string.split(name, '/')[0]
+        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 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
     
-implements(Introspector, IIntrospector)
\ No newline at end of file
+    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 []
+    
+        
+    def getInterfaceDetails(self):
+        """Returns the entire documentation in the interface"""
+        interface = self.context
+        Iname = interface.__name__
+        bases = []
+        desc = ''
+        methods = []
+        attributes = []
+        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
+        


=== Zope3/lib/python/Zope/App/OFS/Introspector/configure.zcml 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Introspector/configure.zcml:1.3	Thu Jun 20 16:00:23 2002
+++ Zope3/lib/python/Zope/App/OFS/Introspector/configure.zcml	Thu Dec 19 13:25:32 2002
@@ -2,20 +2,12 @@
    xmlns='http://namespaces.zope.org/zope'
    xmlns:browser='http://namespaces.zope.org/browser'>
 
-  <permission
-     id="Zope.App.OFS.Introspector.View" 
-     title="View Component Description" />
-
-  <browser:view
-    name="api"
-     permission="Zope.View"
-    factory="Zope.App.OFS.Introspector.
-             Zope.App.OFS.Introspector.Views.Browser.IntrospectorView." />
-
   <adapter
       factory="Zope.App.OFS.Introspector."
       permission="Zope.View"
       provides="Zope.App.OFS.Introspector.IIntrospector." />
+
+  <include package=".Browser" />
 
 </zopeConfigure>