[Checkins] SVN: zope.introspector/trunk/src/zope/introspector/
Merge changes from grokui integration branch.
Uli Fouquet
uli at gnufix.de
Mon Jul 21 08:41:45 EDT 2008
Log message for revision 88649:
Merge changes from grokui integration branch.
Changed:
U zope.introspector/trunk/src/zope/introspector/descriptionprovider.py
U zope.introspector/trunk/src/zope/introspector/descriptionprovider.txt
U zope.introspector/trunk/src/zope/introspector/ftesting.zcml
U zope.introspector/trunk/src/zope/introspector/infoproviders.py
U zope.introspector/trunk/src/zope/introspector/interfaces.py
A zope.introspector/trunk/src/zope/introspector/meta.zcml
U zope.introspector/trunk/src/zope/introspector/objectinfo.py
-=-
Modified: zope.introspector/trunk/src/zope/introspector/descriptionprovider.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/descriptionprovider.py 2008-07-21 10:35:37 UTC (rev 88648)
+++ zope.introspector/trunk/src/zope/introspector/descriptionprovider.py 2008-07-21 12:41:43 UTC (rev 88649)
@@ -25,28 +25,30 @@
class DescriptionFinder(grok.GlobalUtility):
"""Find a description provider.
- Find a component that takes an object and returns some kind of
- info object to describe it.
+ Find a component that takes an object or a dotted name and returns
+ some kind of info object to describe it.
"""
grok.implements(IObjectDescriptionProvider)
- def getDescription(self, obj_or_dotted_path, *args, **kw):
- obj = resolve(obj_or_dotted_path)
+ def getDescription(self, obj=None, dotted_name=None, **kw):
+ if obj is None and dotted_name is not None:
+ obj = resolve(dotted_name)
sorted_reg = sorted(descriptor_registry,
cmp = lambda x,y: x['priority'] - y['priority'])
for descriptor in sorted_reg:
+
handler = descriptor['handler']()
- if handler.canHandle(obj):
- return handler.getDescription(obj)
+ if handler.canHandle(obj, dotted_name=dotted_name):
+ return handler.getDescription(obj, dotted_name=dotted_name)
# If no descriptor could be found, we return the plainest one.
- return ObjectInfo(obj)
+ return ObjectInfo(obj, dotted_name=dotted_name)
class DescriptionProvider(object):
"""Description Providers must inherit from this to be registered.
"""
- def canHandle(self, obj, *args, **kw):
+ def canHandle(self, obj, dotted_name=None, **kw):
return False
- def getDescription(self, obj, *args, **kw):
- return ObjectInfo(obj)
+ def getDescription(self, obj, dotted_name=None, **kw):
+ return ObjectInfo(obj, dotted_name)
Modified: zope.introspector/trunk/src/zope/introspector/descriptionprovider.txt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/descriptionprovider.txt 2008-07-21 10:35:37 UTC (rev 88648)
+++ zope.introspector/trunk/src/zope/introspector/descriptionprovider.txt 2008-07-21 12:41:43 UTC (rev 88649)
@@ -192,7 +192,8 @@
>>> provider
<zope.introspector.descriptionprovider.DescriptionFinder object at 0x...>
-This utility takes objects and returns descriptions for it::
+This utility takes objects or dotted names and returns descriptions
+for it::
>>> provider.getDescription(obj)
<zope.introspector.objectinfo.ObjectInfo object at 0x...>
@@ -205,3 +206,8 @@
>>> provider.getDescription(zope.introspector.tests)
<zope.introspector.objectinfo.PackageInfo object at 0x...>
+We can also pass dotted names to describe the object we want to be
+examined::
+
+ >>> provider.getDescription(dotted_name='zope.introspector.tests')
+ <zope.introspector.objectinfo.PackageInfo object at 0x...>
Modified: zope.introspector/trunk/src/zope/introspector/ftesting.zcml
===================================================================
--- zope.introspector/trunk/src/zope/introspector/ftesting.zcml 2008-07-21 10:35:37 UTC (rev 88648)
+++ zope.introspector/trunk/src/zope/introspector/ftesting.zcml 2008-07-21 12:41:43 UTC (rev 88649)
@@ -13,6 +13,7 @@
<include package="zope.app.authentication" />
<include package="zope.securitypolicy" />
+ <include package="zope.introspector" file="meta.zcml" />
<include package="zope.introspector" />
<securityPolicy
Modified: zope.introspector/trunk/src/zope/introspector/infoproviders.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/infoproviders.py 2008-07-21 10:35:37 UTC (rev 88648)
+++ zope.introspector/trunk/src/zope/introspector/infoproviders.py 2008-07-21 12:41:43 UTC (rev 88649)
@@ -23,20 +23,20 @@
class SimpleDescriptionProvider(DescriptionProvider):
name = 'simple'
priority(1001)
- def getDescription(self, obj, *args, **kw):
- return IObjectInfo(obj)
+ def getDescription(self, obj, dotted_name=None, **kw):
+ return ObjectInfo(obj, dotted_name=dotted_name)
- def canHandle(self, obj, *args, **kw):
+ def canHandle(self, obj, dotted_name=None, **kw):
return True
class PackageDescriptionProvider(DescriptionProvider):
name = 'package'
priority(1000)
- def getDescription(self, obj, *args, **kw):
- return PackageInfo(obj)
+ def getDescription(self, obj, dotted_name=None, **kw):
+ return PackageInfo(obj, dotted_name)
- def canHandle(self, obj, *args, **kw):
+ def canHandle(self, obj=None, dotted_name=None, **kw):
if not inspect.ismodule(obj):
return False
info = martian.scan.module_info_from_module(obj)
Modified: zope.introspector/trunk/src/zope/introspector/interfaces.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/interfaces.py 2008-07-21 10:35:37 UTC (rev 88648)
+++ zope.introspector/trunk/src/zope/introspector/interfaces.py 2008-07-21 12:41:43 UTC (rev 88649)
@@ -158,7 +158,7 @@
class IObjectDescriptionProvider(interface.Interface):
"""Provide description objects for arbitrary objects.
"""
- def getDescription(obj_or_dotted_path, *args, **kw):
+ def getDescription(obj, dotted_name=None, *args, **kw):
"""Get one description object for the object denoted by
- ``obj_or_dotted_path``.
+ ``obj`` or ``dotted_name``.
"""
Copied: zope.introspector/trunk/src/zope/introspector/meta.zcml (from rev 88648, zope.introspector/branches/ulif-grokui-integration/src/zope/introspector/meta.zcml)
===================================================================
--- zope.introspector/trunk/src/zope/introspector/meta.zcml (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/meta.zcml 2008-07-21 12:41:43 UTC (rev 88649)
@@ -0,0 +1,8 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:grok="http://namespaces.zope.org/grok"
+ i18n_domain="zope.introspector">
+
+ <include package="grokcore.component" file="meta.zcml" />
+ <grok:grok package=".meta" />
+
+</configure>
Modified: zope.introspector/trunk/src/zope/introspector/objectinfo.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/objectinfo.py 2008-07-21 10:35:37 UTC (rev 88648)
+++ zope.introspector/trunk/src/zope/introspector/objectinfo.py 2008-07-21 12:41:43 UTC (rev 88649)
@@ -24,10 +24,13 @@
class ObjectInfo(grok.Adapter):
grok.implements(IObjectInfo)
grok.context(Interface)
+
+ dotted_name = None
- def __init__(self, obj):
+ def __init__(self, obj, dotted_name=None):
self.obj = obj
-
+ self.dotted_name = dotted_name
+
def getType(self):
return type(self.obj)
More information about the Checkins
mailing list