[Zope3-checkins] CVS: Zope3/src/zope/app - introspector.py:1.13

Sidnei da Silva sidnei at x3ng.com.br
Mon Aug 11 13:55:26 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv15872

Modified Files:
	introspector.py 
Log Message:
Moved methods from interfacewidget here to avoid import problems

=== Zope3/src/zope/app/introspector.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/introspector.py:1.12	Wed Jul  2 11:22:59 2003
+++ Zope3/src/zope/app/introspector.py	Mon Aug 11 12:55:21 2003
@@ -22,6 +22,7 @@
 from zope.interface import directlyProvides, directlyProvidedBy, providedBy
 from zope.interface.interfaces import IInterface
 from zope.app.services.servicenames import Interfaces
+from zope.component.exceptions import ComponentLookupError
 
 class Introspector:
     """Introspects an object"""
@@ -69,7 +70,7 @@
 
     def getClass(self):
         """Returns the class name"""
-        return (self.currentclass).__name__
+        return removeAllProxies(self.currentclass).__name__
 
     def getBaseClassNames(self):
         """Returns the names of the classes"""
@@ -81,7 +82,7 @@
 
     def getModule(self):
         """Returns the module name of the class"""
-        return (self.currentclass).__module__
+        return removeAllProxies(self.currentclass).__module__
 
     def getDocString(self):
         """Returns the description of the class"""
@@ -96,14 +97,14 @@
             interfaces = self.getInterfaces()
         names = []
         for intObj in interfaces:
-            names.append(intObj.__module__ + '.' + intObj.__name__)
+            names.append(interfaceToName(self.context, intObj))
         names.sort()
         return names
 
     def getInterfaceDetails(self):
         """Returns the entire documentation in the interface"""
         interface = self.context
-        Iname = interface.__name__
+        Iname = interfaceToName(self.context, interface).split('.')[-1]
         bases = []
         desc = ''
         methods = []
@@ -126,7 +127,7 @@
 
     def getExtends(self):
         """Returns all the class extended up to the top most level"""
-        bases = self._unpackTuple((self.currentclass).__bases__)
+        bases = self._unpackTuple(removeAllProxies(self.currentclass).__bases__)
         return bases
 
     def getInterfaceRegistration(self):
@@ -179,7 +180,26 @@
         results = []
         iservice = getService(self.context, Interfaces)
         for id, interface in iservice.items(base=base):
-            if interface.__bases__ == (base,) and not interface.names():
+            if base in interface.getBases() and not interface.names():
                 results.append(interface)
         results.sort()
         return tuple(results)
+
+def nameToInterface(context, name):
+    if name == 'None':
+        return None
+    service = getService(context, Interfaces)
+    return service.getInterface(name)
+
+def interfaceToName(context, interface):
+    interface = removeAllProxies(interface)
+    if interface is None:
+        return 'None'
+    service = getService(context, Interfaces)
+    items = service.items(base=interface)
+    ids = [id for id, iface in items
+           if iface == interface]
+    if not ids:
+        raise ComponentLookupError, interface
+    assert len(ids) == 1, "Ambiguous interface names: %s" % ids
+    return ids[0]




More information about the Zope3-Checkins mailing list