[Checkins]
SVN: zope.introspector/trunk/src/zope/introspector/adapters.py
Copy adapter introspector from Martins sandbox.
Uli Fouquet
uli at gnufix.de
Sat Jun 21 05:04:48 EDT 2008
Log message for revision 87616:
Copy adapter introspector from Martins sandbox.
Changed:
A zope.introspector/trunk/src/zope/introspector/adapters.py
-=-
Copied: zope.introspector/trunk/src/zope/introspector/adapters.py (from rev 87615, Sandbox/mlundwall/zope.introspector/trunk/src/zope/introspector/adapters.py)
===================================================================
--- zope.introspector/trunk/src/zope/introspector/adapters.py (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/adapters.py 2008-06-21 09:04:47 UTC (rev 87616)
@@ -0,0 +1,107 @@
+from zope.interface import implements
+from zope.component import adapts
+from zope.introspector.interfaces import IRegistrySearch
+from zope.component.interfaces import IAdapterRegistration,IHandlerRegistration, IUtilityRegistration
+
+class AdapterSearch(object):
+ implements(IRegistrySearch)
+ adapts(IAdapterRegistration)
+
+ def __init__(self, registration):
+ self.registration = registration
+
+ def searchRegistration(self, string, caseSensitive = False):
+
+ if string in getattr(self.registration.provided, '__name__', ''):
+ return True
+ elif string in self.registration.name:
+ return True
+ elif string in getattr(self.registration.factory, '__name__', ''):
+ return True
+# elif string in self.registration.info:
+# return True
+ else:
+ for each in self.registration.required:
+ if string in getattr(each, '__name__'):
+ return True
+ return False
+
+ def getInterfaces(self):
+ interfaces = []
+ for each in list(self.registration.required) + [self.registration.provided]:
+ module = getattr(each, '__module__')
+ name = getattr(each, '__name__')
+ if module:
+ name = '%s.%s' % (module,name)
+ interfaces.append(name)
+ return interfaces
+
+ def getObject(self):
+ return self.registration
+
+
+class HandlerSearch(object):
+ implements(IRegistrySearch)
+ adapts(IHandlerRegistration)
+
+ def __init__(self, registration):
+ self.registration = registration
+
+ def searchRegistration(self, string, caseSensitive = False):
+
+ if string in self.registration.name:
+ return True
+ elif string in getattr(self.registration.factory, '__name__',''):
+ return True
+# elif string in self.registration.info:
+# return True
+ else:
+ for each in self.registration.required:
+ if string in getattr(each, '__name__'):
+ return True
+ return False
+
+ def getInterfaces(self):
+ interfaces = []
+ for each in list(self.registration.required) + [self.registration.factory]:
+ module = getattr(each, '__module__')
+ name = getattr(each, '__name__')
+ if module:
+ name = '%s.%s' % (module,name)
+ interfaces.append(name)
+ return interfaces
+
+ def getObject(self):
+ return self.registration
+
+
+
+class UtilitySearch(object):
+ implements(IRegistrySearch)
+ adapts(IUtilityRegistration)
+
+ def __init__(self, registration):
+ self.registration = registration
+
+ def searchRegistration(self, string, caseSensitive = False):
+
+ if string in getattr(self.registration.provided, '__name__',''):
+ return True
+ elif string in self.registration.name:
+ return True
+# elif string in self.registration.info:
+# return True
+ return False
+
+ def getInterfaces(self):
+ interfaces = []
+ module = getattr(self.registration.provided, '__module__')
+ name = getattr(self.registration.provided, '__name__')
+ if module:
+ name = '%s.%s' % (module,name)
+ interfaces.append(name)
+ return interfaces
+
+ def getObject(self):
+ return self.registration
+
More information about the Checkins
mailing list