[Checkins] SVN: zope.introspector/trunk/src/zope/introspector/
Added the browser module.
Martin Lundwall
martin at webworks.se
Thu Jun 26 05:13:41 EDT 2008
Log message for revision 87787:
Added the browser module.
Changed:
A zope.introspector/trunk/src/zope/introspector/browser/
A zope.introspector/trunk/src/zope/introspector/browser/__init__.py
A zope.introspector/trunk/src/zope/introspector/browser/adapter.pt
A zope.introspector/trunk/src/zope/introspector/browser/configure.zcml
A zope.introspector/trunk/src/zope/introspector/browser/handler.pt
A zope.introspector/trunk/src/zope/introspector/browser/introspector.py
A zope.introspector/trunk/src/zope/introspector/browser/introspectorbrowse_view.pt
A zope.introspector/trunk/src/zope/introspector/browser/introspectorview.pt
A zope.introspector/trunk/src/zope/introspector/browser/mktree.css
A zope.introspector/trunk/src/zope/introspector/browser/mktree.js
A zope.introspector/trunk/src/zope/introspector/browser/utils.pt
U zope.introspector/trunk/src/zope/introspector/configure.zcml
-=-
Added: zope.introspector/trunk/src/zope/introspector/browser/__init__.py
===================================================================
Added: zope.introspector/trunk/src/zope/introspector/browser/adapter.pt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/adapter.pt (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/adapter.pt 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,48 @@
+<html i18n:domain="zope">
+<body>
+
+<h3>Adapter: <span tal:content="context/name" /></h3>
+
+<div>
+ <div class="indent" tal:define="factory view/getFactory">
+ <h4>Factory</h4>
+ <ul class="attr-list" tal:condition="factory">
+ <li>
+ <div tal:content="factory" />
+ </li>
+ </ul>
+ <div tal:condition="not:factory">
+ No factory found
+ </div>
+ </div>
+
+ <div class="indent"
+ tal:define="provided view/getProvidedInterface">
+ <h4>Provided Interface</h4>
+ <ul class="attr-list" tal:condition="provided">
+ <li>
+ <div tal:content="provided" />
+ </li>
+ </ul>
+ <div tal:condition="not:provided">
+ No interface found
+ </div>
+ </div>
+
+ <div class="indent"
+ tal:define="required view/getRequiredInterfaces">
+ <h4>Required Interfaces</h4>
+ <ul class="attr-list" tal:condition="required">
+ <li tal:repeat="iface required">
+ <a tal:attributes="href string:/@@registry.html/${iface}/@@introspector.html"
+ tal:content="iface">
+ zope.interface.Interface
+ </a>
+ </li>
+ </ul>
+ </div>
+</div>
+<br/>
+
+</body>
+</html>
\ No newline at end of file
Added: zope.introspector/trunk/src/zope/introspector/browser/configure.zcml
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/configure.zcml (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/configure.zcml 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,57 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ i18n_domain="zope.introspector">
+
+ <browser:page
+ for="*"
+ name="registry.html"
+ template="introspectorview.pt"
+ permission="zope.app.apidoc.UseAPIDoc"
+ class=".introspector.Introspector"
+ menu="zmi_views" title="Registry Introspector"
+ />
+
+ <browser:page
+ for="*"
+ name="registry_browser.html"
+ template="introspectorbrowse_view.pt"
+ permission="zope.app.apidoc.UseAPIDoc"
+ class=".introspector.Introspector"
+ />
+
+ <browser:page
+ for="zope.component.interfaces.IAdapterRegistration"
+ name="registration.html"
+ template="adapter.pt"
+ permission="zope.app.apidoc.UseAPIDoc"
+ class=".introspector.RegistrationView"
+ />
+
+ <browser:page
+ for="zope.component.interfaces.IHandlerRegistration"
+ name="registration.html"
+ template="handler.pt"
+ permission="zope.app.apidoc.UseAPIDoc"
+ class=".introspector.RegistrationView"
+ />
+
+ <browser:page
+ for="zope.component.interfaces.IUtilityRegistration"
+ name="registration.html"
+ template="utils.pt"
+ permission="zope.app.apidoc.UseAPIDoc"
+ class=".introspector.RegistrationView"
+ />
+
+ <browser:resource
+ name="mktree.js"
+ file="mktree.js"
+ />
+
+ <browser:resource
+ name="mktree.css"
+ file="mktree.css"
+ />
+
+
+</configure>
\ No newline at end of file
Added: zope.introspector/trunk/src/zope/introspector/browser/handler.pt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/handler.pt (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/handler.pt 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,48 @@
+<html i18n:domain="zope">
+<body>
+
+<h3>Handler: <span tal:content="view/getName" /></h3>
+
+<div>
+ <div class="indent" tal:define="factory view/getFactory">
+ <h4>Factory</h4>
+ <ul class="attr-list" tal:condition="factory">
+ <li>
+ <div tal:content="factory" />
+ </li>
+ </ul>
+ <div tal:condition="not:factory">
+ No factory found
+ </div>
+ </div>
+
+<!-- <div class="indent"-->
+<!-- tal:define="provided view/getProvidedInterface">-->
+<!-- <h4>Provided Interface</h4>-->
+<!-- <ul class="attr-list" tal:condition="provided">-->
+<!-- <li>-->
+<!-- <div tal:content="provided" />-->
+<!-- </li>-->
+<!-- </ul>-->
+<!-- <div tal:condition="not:provided">-->
+<!-- No interface found-->
+<!-- </div>-->
+<!-- </div>-->
+
+ <div class="indent"
+ tal:define="required view/getRequiredInterfaces">
+ <h4>Required Interfaces</h4>
+ <ul class="attr-list" tal:condition="required">
+ <li tal:repeat="iface required">
+ <a tal:attributes="href string:/@@registry.html/${iface}/@@introspector.html"
+ tal:content="iface">
+ zope.interface.Interface
+ </a>
+ </li>
+ </ul>
+ </div>
+</div>
+<br/>
+
+</body>
+</html>
\ No newline at end of file
Added: zope.introspector/trunk/src/zope/introspector/browser/introspector.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/introspector.py (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/introspector.py 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,115 @@
+from zope.publisher.browser import BrowserView
+from zope.app.zapi import getUtility
+from zope.dottedname import resolve
+from zope.interface import Interface, implements
+from zope.traversing.interfaces import ITraversable
+from zope.traversing.adapters import DefaultTraversable
+from zope.component import adapts
+
+from zope.introspector.interfaces import IRegistryInfo
+
+class RegistrationView(BrowserView):
+ """
+ """
+
+ def _expandPath(self, obj):
+ module = getattr(obj, '__module__')
+ name = getattr(obj, '__name__')
+ if module:
+ name = '%s.%s' % (module,name)
+ return name
+
+ def getFactory(self):
+ return getattr(self.context.factory, '__name__', '')
+
+ def getProvidedInterface(self):
+ return self._expandPath(self.context.provided)
+
+ def getName(self):
+ return self.context.name.split('.')[-1]
+
+ def getRequiredInterfaces(self):
+ return [self._expandPath(x) for x in self.context.required]
+
+class Introspector(BrowserView):
+
+
+ def getAll(self):
+ return getUtility(IRegistryInfo).getAllInterfaces()
+
+ def getUtilities(self):
+ return getUtility(IRegistryInfo).getAllUtilities()
+
+ def getAdapters(self):
+ return getUtility(IRegistryInfo).getAllAdapters()
+
+ def getHandlers(self):
+ return getUtility(IRegistryInfo).getAllHandlers()
+
+ def searchRegistry(self):
+ form = self.request.form
+
+ search = form.get('searchQuery')
+ if not search:
+ return
+
+ types = []
+ if form.get('adapters'):
+ types.append('adapters')
+ if form.get('utilities'):
+ types.append('utilities')
+ if form.get('handlers'):
+ types.append('handlers')
+ if form.get('subscriptionAdapters'):
+ types.append('subscriptionAdapters')
+
+ registry = getUtility(IRegistryInfo)
+ return registry.getRegistrationsForInterface(search, types)
+
+ def generateHTMLTree(self):
+ return '<ul class="mktree" id="treeBrowse">' + self._generator(self.getAll()) + '</ul>'
+
+ def _generator(self, tree):
+ page = ""
+ tags = {}
+ tags['base_start'] = '<ul>'
+ tags['base_end'] = '</ul>'
+ tags['list_start'] = '<li>'
+ tags['list_end'] = '</li>'
+
+ if not isinstance(tree, dict):
+ return tree
+ for key in tree.keys():
+ returned = self._generator(tree[key])
+ if isinstance(returned, str):
+ # we are still in the dictionary
+ page = page + tags['list_start'] + key
+ page = page + tags['base_start']
+ page = page + returned
+ page = page + tags['base_end']
+ page = page + tags['list_end']
+ else:
+ # we are at a end node, leaf
+ page = page + tags['list_start'] + key
+ page = page + '<ul class="interfaceList">'
+
+ if isinstance(returned, list):
+ for interface in returned:
+
+ page = page + tags['list_start'] + str(interface) + tags['list_end']
+ #page = page + tags['list_start'] + self.traverse(interface, '@@registration.html')() + tags['list_end']
+ page = page + '</ul>'
+ page = page + tags['list_end']
+ return page
+
+ def publishTraverse(self, request, name):
+ from zope.publisher.interfaces import NotFound
+ try:
+ return super(Introspector, self).publishTraverse(request, name)
+ except NotFound:
+ obj = resolve.resolve(name)
+ from zope.location.location import LocationProxy
+ return LocationProxy(obj, container=self, name=name)
+
+
+
\ No newline at end of file
Added: zope.introspector/trunk/src/zope/introspector/browser/introspectorbrowse_view.pt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/introspectorbrowse_view.pt (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/introspectorbrowse_view.pt 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,39 @@
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+<head>
+<div metal:fill-slot="style_slot">
+
+ <script type="text/javascript"
+ src="mktree.js"
+ tal:attributes="src string:${context/++resource++mktree.js}"
+ >
+ </script>
+ <style type="text/css"
+ tal:content="string:@import url(${context/++resource++mktree.css});">
+ @import url(mktree.css);
+ </style>
+
+ </div>
+</head>
+<body>
+<div metal:fill-slot="body">
+
+ <h1 i18n:translate="">
+ Registry Browser:
+ </h1>
+
+
+ <div class="indent"
+ tal:content="structure view/generateHTMLTree">
+
+<!-- <ul class="attr-list" tal:condition="results">-->
+<!-- <li tal:repeat="result results">-->
+<!-- <span tal:content="result" />-->
+<!-- </li>-->
+<!-- </ul>-->
+
+ </div>
+
+</div>
+</body>
+</html>
Added: zope.introspector/trunk/src/zope/introspector/browser/introspectorview.pt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/introspectorview.pt (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/introspectorview.pt 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,75 @@
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+<body>
+<div metal:fill-slot="body">
+
+ <h1 i18n:translate="">
+ Registry Introspector: <a tal:attributes="href string:${context/@@absolute_url}/@@registry_browser.html">Browse</a>
+ </h1>
+
+<!-- <h2 i18n:translate=""-->
+<!-- tal:define="utils view/getUtilities">-->
+<!-- Registered Utilities:-->
+<!-- <span tal:content="python:len(utils)">-->
+<!-- </span>-->
+<!-- </h2>-->
+
+ <form action="request/URL"
+ tal:attributes="action request/URL"
+ method="post"
+ >
+
+ <div class="row">
+ <div class="label" i18n:translate="">Search Registry</div>
+ <div class="field">
+ <input type="text"
+ name="searchQuery"
+ size="50"
+ tal:attributes="value request/searchQuery | nothing"
+ />
+ </div>
+ <div class="field">
+ Adapters
+ <input type="checkbox"
+ name="adapters"
+ tal:attributes="checked request/adapters | nothing"
+ />
+ Utilities
+ <input type="checkbox"
+ name="utilities"
+ tal:attributes="checked request/utilities | nothing"
+ />
+ Handlers
+ <input type="checkbox"
+ name="handlers"
+ tal:attributes="checked request/handlers | nothing"
+ />
+ Subscription Adapters
+ <input type="checkbox"
+ name="subscriptionAdapters"
+ tal:attributes="checked request/subscriptionAdapters | nothing"
+ />
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="controls">
+ <input type="submit" name="search" value="Search"/>
+ </div>
+ </div>
+ </form>
+
+ <div class="indent"
+ tal:define="results view/searchRegistry">
+
+ <ul class="attr-list" tal:condition="results">
+ <li tal:repeat="result results">
+ <span tal:content="structure result/@@registration.html" />
+ </li>
+ </ul>
+
+ </div>
+
+</div>
+</body>
+</html>
Added: zope.introspector/trunk/src/zope/introspector/browser/mktree.css
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/mktree.css (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/mktree.css 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,23 @@
+/* Put this inside a @media qualifier so Netscape 4 ignores it */
+ at media screen, print {
+ /* Turn off list bullets */
+ ul.mktree li { list-style: none; }
+ /* Control how "spaced out" the tree is */
+ ul.mktree, ul.mktree ul , ul.mktree li { margin-left:10px; padding:0px; }
+ /* Provide space for our own "bullet" inside the LI */
+ ul.mktree li .bullet { padding-left: 15px; }
+ /* Show "bullets" in the links, depending on the class of the LI that the link's in */
+ ul.mktree li.liOpen .bullet { cursor: pointer; background: url(minus.gif) center left no-repeat; }
+ ul.mktree li.liClosed .bullet { cursor: pointer; background: url(plus.gif) center left no-repeat; }
+ ul.mktree li.liBullet .bullet { cursor: default; background: url(item.gif) center left no-repeat; }
+ /* Sublists are visible or not based on class of parent LI */
+ ul.mktree li.liOpen ul { display: block; }
+ ul.mktree li.liClosed ul { display: none; }
+
+ /* Format menu items differently depending on what level of the tree they are in */
+ /* Uncomment this if you want your fonts to decrease in size the deeper they are in the tree */
+/*
+ ul.mktree li ul li { font-size: 90% }
+*/
+
+}
Added: zope.introspector/trunk/src/zope/introspector/browser/mktree.js
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/mktree.js (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/mktree.js 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,168 @@
+/**
+ * Copyright (c)2005-2007 Matt Kruse (javascripttoolbox.com)
+ *
+ * Dual licensed under the MIT and GPL licenses.
+ * This basically means you can use this code however you want for
+ * free, but don't claim to have written it yourself!
+ * Donations always accepted: http://www.JavascriptToolbox.com/donate/
+ *
+ * Please do not link to the .js files on javascripttoolbox.com from
+ * your site. Copy the files locally to your server instead.
+ *
+ */
+/*
+This code is inspired by and extended from Stuart Langridge's aqlist code:
+ http://www.kryogenix.org/code/browser/aqlists/
+ Stuart Langridge, November 2002
+ sil at kryogenix.org
+ Inspired by Aaron's labels.js (http://youngpup.net/demos/labels/)
+ and Dave Lindquist's menuDropDown.js (http://www.gazingus.org/dhtml/?id=109)
+*/
+
+// Automatically attach a listener to the window onload, to convert the trees
+addEvent(window,"load",convertTrees);
+
+// Utility function to add an event listener
+function addEvent(o,e,f){
+ if (o.addEventListener){ o.addEventListener(e,f,false); return true; }
+ else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
+ else { return false; }
+}
+
+// utility function to set a global variable if it is not already set
+function setDefault(name,val) {
+ if (typeof(window[name])=="undefined" || window[name]==null) {
+ window[name]=val;
+ }
+}
+
+// Full expands a tree with a given ID
+function expandTree(treeId) {
+ var ul = document.getElementById(treeId);
+ if (ul == null) { return false; }
+ expandCollapseList(ul,nodeOpenClass);
+}
+
+// Fully collapses a tree with a given ID
+function collapseTree(treeId) {
+ var ul = document.getElementById(treeId);
+ if (ul == null) { return false; }
+ expandCollapseList(ul,nodeClosedClass);
+}
+
+// Expands enough nodes to expose an LI with a given ID
+function expandToItem(treeId,itemId) {
+ var ul = document.getElementById(treeId);
+ if (ul == null) { return false; }
+ var ret = expandCollapseList(ul,nodeOpenClass,itemId);
+ if (ret) {
+ var o = document.getElementById(itemId);
+ if (o.scrollIntoView) {
+ o.scrollIntoView(false);
+ }
+ }
+}
+
+// Performs 3 functions:
+// a) Expand all nodes
+// b) Collapse all nodes
+// c) Expand all nodes to reach a certain ID
+function expandCollapseList(ul,cName,itemId) {
+ if (!ul.childNodes || ul.childNodes.length==0) { return false; }
+ // Iterate LIs
+ for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
+ var item = ul.childNodes[itemi];
+ if (itemId!=null && item.id==itemId) { return true; }
+ if (item.nodeName == "LI") {
+ // Iterate things in this LI
+ var subLists = false;
+ for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
+ var sitem = item.childNodes[sitemi];
+ if (sitem.nodeName=="UL") {
+ subLists = true;
+ var ret = expandCollapseList(sitem,cName,itemId);
+ if (itemId!=null && ret) {
+ item.className=cName;
+ return true;
+ }
+ }
+ }
+ if (subLists && itemId==null) {
+ item.className = cName;
+ }
+ }
+ }
+}
+
+// Search the document for UL elements with the correct CLASS name, then process them
+function convertTrees() {
+ setDefault("treeClass","mktree");
+ setDefault("nodeClosedClass","liClosed");
+ setDefault("nodeOpenClass","liOpen");
+ setDefault("nodeBulletClass","liBullet");
+ setDefault("nodeLinkClass","bullet");
+ setDefault("preProcessTrees",true);
+ if (preProcessTrees) {
+ if (!document.createElement) { return; } // Without createElement, we can't do anything
+ var uls = document.getElementsByTagName("ul");
+ if (uls==null) { return; }
+ var uls_length = uls.length;
+ for (var uli=0;uli<uls_length;uli++) {
+ var ul=uls[uli];
+ if (ul.nodeName=="UL" && ul.className==treeClass) {
+ processList(ul);
+ }
+ }
+ }
+}
+
+function treeNodeOnclick() {
+ this.parentNode.className = (this.parentNode.className==nodeOpenClass) ? nodeClosedClass : nodeOpenClass;
+ return false;
+}
+function retFalse() {
+ return false;
+}
+// Process a UL tag and all its children, to convert to a tree
+function processList(ul) {
+ if (!ul.childNodes || ul.childNodes.length==0) { return; }
+ // Iterate LIs
+ var childNodesLength = ul.childNodes.length;
+ for (var itemi=0;itemi<childNodesLength;itemi++) {
+ var item = ul.childNodes[itemi];
+ if (item.nodeName == "LI") {
+ // Iterate things in this LI
+ var subLists = false;
+ var itemChildNodesLength = item.childNodes.length;
+ for (var sitemi=0;sitemi<itemChildNodesLength;sitemi++) {
+ var sitem = item.childNodes[sitemi];
+ if (sitem.nodeName=="UL") {
+ subLists = true;
+ processList(sitem);
+ }
+ }
+ var s= document.createElement("SPAN");
+ var t= '\u00A0'; //
+ s.className = nodeLinkClass;
+ if (subLists) {
+ // This LI has UL's in it, so it's a +/- node
+ if (item.className==null || item.className=="") {
+ item.className = nodeClosedClass;
+ }
+ // If it's just text, make the text work as the link also
+ if (item.firstChild.nodeName=="#text") {
+ t = t+item.firstChild.nodeValue;
+ item.removeChild(item.firstChild);
+ }
+ s.onclick = treeNodeOnclick;
+ }
+ else {
+ // No sublists, so it's just a bullet node
+ item.className = nodeBulletClass;
+ s.onclick = retFalse;
+ }
+ s.appendChild(document.createTextNode(t));
+ item.insertBefore(s,item.firstChild);
+ }
+ }
+}
Added: zope.introspector/trunk/src/zope/introspector/browser/utils.pt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/browser/utils.pt (rev 0)
+++ zope.introspector/trunk/src/zope/introspector/browser/utils.pt 2008-06-26 09:13:40 UTC (rev 87787)
@@ -0,0 +1,34 @@
+<html i18n:domain="zope">
+<body>
+
+<h3>Utility: <span tal:content="view/getName" /></h3>
+
+<div>
+ <div class="ident">
+ <h4>Component</h4>
+ <div tal:content="context/name" />
+ <div tal:condition="not: context/name">
+ Unnamed Utility
+ </div>
+ </div>
+
+ <div class="indent"
+ tal:define="provided view/getProvidedInterface">
+ <h4>Provided Interface</h4>
+ <ul class="attr-list" tal:condition="provided">
+ <li>
+ <a tal:attributes="href string:/@@registry.html/${provided}/@@introspector.html"
+ tal:content="provided">
+ zope.interface.Interface
+ </a>
+ </li>
+ </ul>
+ <div tal:condition="not:provided">
+ No interface found
+ </div>
+ </div>
+</div>
+<br/>
+
+</body>
+</html>
\ No newline at end of file
Modified: zope.introspector/trunk/src/zope/introspector/configure.zcml
===================================================================
--- zope.introspector/trunk/src/zope/introspector/configure.zcml 2008-06-26 08:42:53 UTC (rev 87786)
+++ zope.introspector/trunk/src/zope/introspector/configure.zcml 2008-06-26 09:13:40 UTC (rev 87787)
@@ -5,5 +5,6 @@
<include package="grokcore.component" file="meta.zcml" />
<grok:grok package="." />
-
+ <include package=".browser" />
+
</configure>
More information about the Checkins
mailing list