[Zope3-checkins]
SVN: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/
add support for interfaces directly provided by objects to
the introspector
Fred L. Drake, Jr.
fdrake at gmail.com
Wed Mar 16 14:48:19 EST 2005
Log message for revision 29514:
add support for interfaces directly provided by objects to the introspector
Changed:
U Zope3/trunk/src/zope/app/apidoc/codemodule/browser/README.txt
U Zope3/trunk/src/zope/app/apidoc/codemodule/browser/configure.zcml
U Zope3/trunk/src/zope/app/apidoc/codemodule/browser/ftests.py
A Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.pt
U Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py
A Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.txt
-=-
Modified: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/README.txt 2005-03-16 19:47:37 UTC (rev 29513)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/README.txt 2005-03-16 19:48:19 UTC (rev 29514)
@@ -390,13 +390,27 @@
>>> class Content(object):
... pass
+ >>> Content.__module__ = 'module.name.here'
+
we can generate the introspector redirector like this:
>>> from zope.app.apidoc.codemodule.browser import introspector
>>> request = TestRequest()
>>> view = introspector.Introspector(Content(), request)
- >>> view()
- >>> request.response.getHeader('Location')
- 'http://127.0.0.1/++apidoc++/Code/__builtin__/Content/index.html'
+ >>> view.class_name()
+ 'module.name.here.Content'
+ >>> view.class_url()
+ 'http://127.0.0.1/++apidoc++/Code/module/name/here/Content/index.html'
+ >>> view.direct_interfaces()
+ []
+If the instance directly provides any interfaces, these are reported
+as well:
+ >>> import zope.interface
+ >>> zope.interface.directlyProvides(view.context,
+ ... IDocumentationModule)
+ >>> pprint(view.direct_interfaces())
+ [{'module': 'zope.app.apidoc.interfaces',
+ 'name': 'IDocumentationModule',
+ 'url': 'http://127.0.0.1/++apidoc++/Interface/zope.app.apidoc.interfaces.IDocumentationModule/apiindex.html'}]
Modified: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/configure.zcml 2005-03-16 19:47:37 UTC (rev 29513)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/configure.zcml 2005-03-16 19:48:19 UTC (rev 29514)
@@ -59,6 +59,7 @@
class=".introspector.Introspector"
permission="zope.ManageContent"
menu="zmi_views" title="Introspector"
+ template="introspector.pt"
/>
</configure>
Modified: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/ftests.py 2005-03-16 19:47:37 UTC (rev 29513)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/ftests.py 2005-03-16 19:48:19 UTC (rev 29514)
@@ -16,7 +16,9 @@
$Id$
"""
import unittest
+
from zope.app.testing.functional import BrowserTestCase
+from zope.app.testing.functional import FunctionalDocFileSuite
class CodeModuleTests(BrowserTestCase):
"""Just a couple of tests ensuring that the templates render."""
@@ -96,6 +98,7 @@
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(CodeModuleTests),
+ FunctionalDocFileSuite("introspector.txt"),
))
if __name__ == '__main__':
Added: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.pt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.pt 2005-03-16 19:47:37 UTC (rev 29513)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.pt 2005-03-16 19:48:19 UTC (rev 29514)
@@ -0,0 +1,30 @@
+<html metal:use-macro="views/standard_macros/view">
+<body>
+<div metal:fill-slot="body">
+
+<div class="row">
+ <div class="label" i18n:translate="">Class</div>
+ <div class="field">
+ <a tal:attributes="href view/class_url"
+ tal:content="view/class_name"/>
+ </div>
+</div>
+
+<div class="row"
+ tal:define="interfaces view/direct_interfaces"
+ tal:condition="interfaces">
+ <div class="label" i18n:translate="">Directly provided interfaces</div>
+ <div class="field">
+ <ul>
+ <li tal:repeat="iface interfaces"><a tal:attributes="href iface/url"
+ ><tal:span replace="iface/module"
+ />.<tal:span replace="iface/name"/></a></li>
+ </ul>
+ </div>
+</div>
+
+<div class="row"></div>
+
+</div>
+</body>
+</html>
Property changes on: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.pt
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py 2005-03-16 19:47:37 UTC (rev 29513)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py 2005-03-16 19:48:19 UTC (rev 29514)
@@ -16,15 +16,36 @@
$Id: browser.py 29143 2005-02-14 22:43:16Z srichter $
"""
__docformat__ = 'restructuredtext'
+
+import zope.interface
+
from zope.security.proxy import removeSecurityProxy
from zope.app.publisher.browser import BrowserView
class Introspector(BrowserView):
- def __call__(self):
+ def class_name(self):
klass = type(removeSecurityProxy(self.context))
+ return "%s.%s" % (klass.__module__, klass.__name__)
+
+ def class_url(self):
+ klass = type(removeSecurityProxy(self.context))
url = self.request.getApplicationURL() + '/++apidoc++/Code/'
url += klass.__module__.replace('.', '/') + '/'
- url += klass.__name__ + '/index.html'
- self.request.response.redirect(url)
+ return url + klass.__name__ + '/index.html'
+
+ def direct_interfaces(self):
+ ob = removeSecurityProxy(self.context)
+ ifaces = zope.interface.directlyProvidedBy(ob)
+ result = []
+ urlbase = self.request.getApplicationURL() + '/++apidoc++/Interface/'
+ for iface in ifaces:
+ url = "%s%s.%s/apiindex.html" % (
+ urlbase, iface.__module__, iface.__name__)
+ result.append(("%s.%s" % (iface.__module__, iface.__name__),
+ {"name": iface.__name__,
+ "module": iface.__module__,
+ "url": url}))
+ result.sort()
+ return [dict for name, dict in result]
Added: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.txt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.txt 2005-03-16 19:47:37 UTC (rev 29513)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.txt 2005-03-16 19:48:19 UTC (rev 29514)
@@ -0,0 +1,43 @@
+========================
+Object Introspector View
+========================
+
+The "Introspector" view provides access to information about the class
+that implements an object and the interfaces that the object provides
+directly.
+
+::
+
+ >>> response = str(http("""
+ ... GET /@@introspector.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """))
+
+ >>> print response
+ HTTP/1.1 200 Ok
+ ...
+
+The class information is provided as a link from the class name to the
+introspection page for the class::
+
+ >>> ("http://localhost/++apidoc++/Code/"
+ ... "zope/app/folder/folder/Folder/index.html") in response
+ True
+ >>> "zope.app.folder.folder.Folder" in response
+ True
+
+Information about the directly provided information is provided by
+links from the provided interface names to the introspection pages for
+the interfaces::
+
+ >>> ("http://localhost/++apidoc++/Interface/"
+ ... "zope.app.component.interfaces.ISite/apiindex.html") in response
+ True
+ >>> ">zope.app.component.interfaces.ISite</" in response
+ True
+
+ >>> ("http://localhost/++apidoc++/Interface/"
+ ... "zope.app.folder.interfaces.IRootFolder/apiindex.html") in response
+ True
+ >>> ">zope.app.folder.interfaces.IRootFolder</" in response
+ True
Property changes on: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
More information about the Zope3-Checkins
mailing list