[Zope3-checkins] CVS: Zope3/src/zope/app/introspector -
__init__.py:1.3 browser.py:1.2
Suresh Babu Eddala
sbabu at zeomega.com
Fri Mar 5 10:55:09 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/introspector
In directory cvs.zope.org:/tmp/cvs-serv11790/src/zope/app/introspector
Modified Files:
__init__.py browser.py
Log Message:
removed local interface service stuff, it uses global utility service.
=== Zope3/src/zope/app/introspector/__init__.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/introspector/__init__.py:1.2 Wed Mar 3 12:06:57 2004
+++ Zope3/src/zope/app/introspector/__init__.py Fri Mar 5 10:54:39 2004
@@ -15,18 +15,16 @@
$Id$
"""
+from zope.interface import Interface
+from zope.app.introspector.interfaces import IIntrospector
+from zope.app.interfaces.services.module import IModuleService
from zope.component import getService, getAdapter, getServiceDefinitions
from zope.proxy import removeAllProxies
-
-from zope.interface import Interface, implements, implementedBy
+from zope.interface import implements, implementedBy
from zope.interface import directlyProvides, directlyProvidedBy, providedBy
from zope.interface.interfaces import IInterface
from zope.interface.interface import InterfaceClass
-
-from zope.app.interfaces.services.module import IModuleService
-from zope.app.services.servicenames import Interfaces
-
-from zope.app.introspector.interfaces import IIntrospector
+from zope.app.component.interface import searchInterface, getInterface
class Introspector(object):
"""Introspects an object"""
@@ -159,10 +157,10 @@
def getMarkerInterfaces(self):
"""See IIntrospector"""
+
results = []
todo = list(providedBy(removeAllProxies(self.context)))
done = []
-
while todo:
interface = todo.pop()
done.append(interface)
@@ -180,48 +178,35 @@
def getDirectMarkersOf(self, base):
"""Returns empty interfaces directly inheriting from the given one"""
+
results = []
- iservice = getService(self.context, Interfaces)
- for id, interface in iservice.items(base=base):
+ interfaces = searchInterface(self.context, base=base)
+ for interface in interfaces:
# There are things registered with the interface service
# that are not interfaces. Yay!
if not IInterface.isImplementedBy(interface):
continue
if base in interface.__bases__ 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)
- iface = service.getInterface(name)
- return iface
+
def interfaceToName(context, interface):
interface = removeAllProxies(interface)
if interface is None:
return 'None'
- defaultName = interface.__module__ + '.' + interface.getName()
- service = getService(context, Interfaces)
- items = service.items(base=interface)
- ids = [id for id, iface in items
+ items = searchInterface(context, base=interface)
+ ids = [('%s.%s' %(iface.__module__, iface.__name__))
+ for iface in items
if iface == interface]
+
if not ids:
# XXX Do not fail badly, instead resort to the standard
# way of getting the interface name, cause not all interfaces
# may be registered.
- return defaultName
-
- if len(ids) == 1:
- return ids[0]
+ return interface.__module__ + '.' + interface.getName()
- # XXX: Band-aid for mal-functioning interface service. Once the interface
- # service is gone, this method needs to be refactored anyways and the
- # following two lines should be removed!!!
- if defaultName in ids:
- return defaultName
-
assert len(ids) == 1, "Ambiguous interface names: %s" % ids
-
+ return ids[0]
=== Zope3/src/zope/app/introspector/browser.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/introspector/browser.py:1.1 Mon Mar 1 05:18:20 2004
+++ Zope3/src/zope/app/introspector/browser.py Fri Mar 5 10:54:39 2004
@@ -15,27 +15,29 @@
$Id$
"""
-from zope.proxy import removeAllProxies
-from zope.interface import directlyProvides, directlyProvidedBy
-from zope.component.exceptions import ComponentLookupError
-
-from zope.app import zapi
from zope.app.publisher.browser import BrowserView
-from zope.app.services.servicenames import Interfaces
from zope.app.introspector.interfaces import IIntrospector
+from zope.component import getAdapter
+from zope.app import zapi
+from zope.component.exceptions import ComponentLookupError
+from zope.interface import directlyProvides, directlyProvidedBy
+from zope.proxy import removeAllProxies
+from zope.app.component.interface import getInterface
+from zope.app.services.servicenames import Services
+
class IntrospectorView(BrowserView):
def getIntrospector(self):
- introspector = zapi.getAdapter(self.context, IIntrospector)
+ introspector = getAdapter(self.context, IIntrospector)
introspector.setRequest(self.request)
return introspector
def getInterfaceURL(self, name):
- interfaces = zapi.getService(self.context, Interfaces)
+ services = zapi.getService(self.context, Services)
try:
- interfaces.getInterface(name)
- url = zapi.getView(interfaces, 'absolute_url', self.request)
+ getInterface(self.context, name)
+ url = zapi.getView(services, 'absolute_url', self.request)
return "%s/detail.html?id=%s" % (url, name)
except ComponentLookupError:
return ""
@@ -44,30 +46,28 @@
if 'ADD' in self.request:
for interface in self.getIntrospector().getMarkerInterfaceNames():
if "add_%s" % interface in self.request:
- interfaces = zapi.getService(self.context, Interfaces)
- interface = interfaces.getInterface(interface)
+ interface = getInterface(self.context, interface)
ob = removeAllProxies(self.context)
directlyProvides(ob, directlyProvidedBy(ob), interface)
if 'REMOVE' in self.request:
for interface in self.getIntrospector().getDirectlyProvidedNames():
if "rem_%s" % interface in self.request:
- interfaces = zapi.getService(self.context, Interfaces)
- interface = interfaces.getInterface(interface)
+ interface = getInterface(self.context, interface)
ob = removeAllProxies(self.context)
directlyProvides(ob, directlyProvidedBy(ob)-interface)
def getServicesFor(self):
services = []
- #sm = zapi.getServiceManager(self.context)
+ #sm = getServiceManager(self.context)
#for stype, interface in sm.getServiceDefinitions():
# try:
- # service = zapi.getService(self.context, stype)
+ # service = getService(self.context, stype)
# except ComponentLookupError:
# pass
# else:
# # XXX IConfigureFor appears to have disappeared at some point
- # adapter = zapi.queryAdapter(service, IConfigureFor)
+ # adapter = queryAdapter(service, IConfigureFor)
# if (adapter is not None
# and adapter.hasRegistrationFor(self.context)):
# search_result = service.getRegisteredMatching(
More information about the Zope3-Checkins
mailing list