[Zope3-checkins] SVN: Zope3/trunk/ Deprecated zope.app.introspector.

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Feb 28 08:42:02 EST 2005


Log message for revision 29341:
  Deprecated zope.app.introspector.
  
  Addressed issue 374.
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/apidoc/codemodule/browser/README.txt
  U   Zope3/trunk/src/zope/app/apidoc/codemodule/browser/configure.zcml
  A   Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py
  U   Zope3/trunk/src/zope/app/apidoc/codemodule/browser/tests.py
  U   Zope3/trunk/src/zope/app/component/interface.py
  U   Zope3/trunk/src/zope/app/ftests/test_introspector.py
  U   Zope3/trunk/src/zope/app/interface/vocabulary.py
  U   Zope3/trunk/src/zope/app/introspector/__init__.py
  U   Zope3/trunk/src/zope/app/introspector/browser.py
  U   Zope3/trunk/src/zope/app/introspector/configure.zcml
  U   Zope3/trunk/src/zope/app/introspector/tests/test_introspector.py
  U   Zope3/trunk/src/zope/app/introspector/tests/test_introspectorview.py
  U   Zope3/trunk/src/zope/app/workflow/stateful/browser/contentworkflow.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/doc/CHANGES.txt	2005-02-28 13:42:02 UTC (rev 29341)
@@ -288,6 +288,10 @@
 
     Restructuring
 
+      - Deprecated `zope.app.introspector`. You should use the public apidoc
+        utilities isntead. A new "Introspector" tab was implemented that
+        redirects you to the correct code browser documentation screen.
+
       - Ensured that all adapters can be registered for classes as well as
         interfaces by writing tests for all adapter-based directives. It
         turned out that subscribers did not accept classes yet, so I

Modified: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/README.txt	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/README.txt	2005-02-28 13:42:02 UTC (rev 29341)
@@ -375,4 +375,28 @@
 
   >>> details.getElements()
   [<Directive (u'http://namespaces.zope.org/zope', u'allow')>]
- 
\ No newline at end of file
+ 
+
+The Introspector View
+---------------------
+
+In order to allow the quick lookup of documentation from the content
+components themselves, a special "Introspector" tab is added for all content
+types. When clicked, it will forward you to the appropriate code browser
+documentation screen. 
+
+So for a given content type:
+
+  >>> class Content(object):
+  ...    pass
+
+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'
+
+

Modified: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/configure.zcml	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/configure.zcml	2005-02-28 13:42:02 UTC (rev 29341)
@@ -1,6 +1,7 @@
 <configure
     xmlns="http://namespaces.zope.org/browser"
-    xmlns:zope="http://namespaces.zope.org/zope">
+    xmlns:zope="http://namespaces.zope.org/zope"
+    i18n_domain="zope">
 
   <page
       for="..codemodule.CodeModule"
@@ -51,4 +52,13 @@
       class=".zcml.DirectiveDetails"
       permission="zope.ManageContent"/>
 
+  <!-- Introspector -->
+  <page
+      name="introspector.html"
+      for="*"
+      class=".introspector.Introspector"
+      permission="zope.ManageContent"
+      menu="zmi_views" title="Introspector"
+      />
+
 </configure>

Added: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Introspector view for content components
+
+$Id: browser.py 29143 2005-02-14 22:43:16Z srichter $
+"""
+__docformat__ = 'restructuredtext'
+from zope.security.proxy import removeSecurityProxy
+from zope.app.publisher.browser import BrowserView
+
+
+class Introspector(BrowserView):
+
+    def __call__(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)


Property changes on: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/introspector.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/trunk/src/zope/app/apidoc/codemodule/browser/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/codemodule/browser/tests.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/apidoc/codemodule/browser/tests.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -22,6 +22,7 @@
 from zope.interface import directlyProvides, implements
 from zope.testing import doctest, doctestunit
 
+import zope.app
 import zope.app.appsetup.appsetup
 from zope.app.renderer.rest import ReStructuredTextSourceFactory
 from zope.app.renderer.rest import IReStructuredTextSource
@@ -45,6 +46,14 @@
     """This is the foo function."""
 foo.deprecated = True
 
+meta = '''
+<configure i18n_domain="zope">
+  <include package="zope.app" file="meta.zcml" />
+  <include package="zope.app.apidoc" file="meta.zcml" />
+  <include package="zope.app" file="menus.zcml" />
+</configure>
+'''
+
 def setUp(test):
     placelesssetup.setUp()
     setup.setUpTraversal()
@@ -72,10 +81,7 @@
     ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
                          'zope.source.stx')
 
-    meta = os.path.join(os.path.dirname(zope.app.__file__), 'meta.zcml')
-    context = xmlconfig.file(meta, zope.app)
-    meta = os.path.join(os.path.dirname(zope.app.apidoc.__file__), 'meta.zcml')
-    context = xmlconfig.file(meta, zope.app.apidoc, context)
+    context = xmlconfig.string(meta)
 
     # Fix up path for tests.
     global old_context

Modified: Zope3/trunk/src/zope/app/component/interface.py
===================================================================
--- Zope3/trunk/src/zope/app/component/interface.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/component/interface.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -246,3 +246,20 @@
     iface = getInterface(context, id)
     return iface
 
+def interfaceToName(context, interface):
+    if interface is None:
+        return 'None'
+    items = searchInterface(context, base=interface)
+    ids = [('%s.%s' %(iface.__module__, iface.__name__))
+           for iface in items
+           if iface == interface]
+    
+    if not ids:
+        # Do not fail badly, instead resort to the standard
+        # way of getting the interface name, cause not all interfaces
+        # may be registered as utilities.
+        return interface.__module__ + '.' + interface.__name__
+
+    assert len(ids) == 1, "Ambiguous interface names: %s" % ids
+    return ids[0]
+

Modified: Zope3/trunk/src/zope/app/ftests/test_introspector.py
===================================================================
--- Zope3/trunk/src/zope/app/ftests/test_introspector.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/ftests/test_introspector.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -24,9 +24,8 @@
 class TestIntrospector(BrowserTestCase):
 
     def test_introspector(self):
-        response = self.publish('/@@classBrowser.html', basic='mgr:mgrpw')
-        self.checkForBrokenLinks(response.getBody(), response.getPath(),
-                                 basic='mgr:mgrpw')
+        response = self.publish('/@@introspector.html', basic='mgr:mgrpw')
+        self.assertEquals(response.getStatus(), 302)
 
 def test_suite():
     suite = unittest.TestSuite()

Modified: Zope3/trunk/src/zope/app/interface/vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/app/interface/vocabulary.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/interface/vocabulary.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -20,7 +20,7 @@
 from zope.interface import providedBy
 from zope.security.proxy import removeSecurityProxy
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 
-from zope.app.introspector import interfaceToName
+from zope.app.component.interface import interfaceToName
 
 
 class ObjectInterfacesVocabulary(SimpleVocabulary):

Modified: Zope3/trunk/src/zope/app/introspector/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/introspector/__init__.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/introspector/__init__.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -81,7 +81,7 @@
         base_names = []
         for base in bases:
             base_names.append(base.__module__+'.'+base.__name__)
-        return base_names
+            return base_names
 
     def getModule(self):
         """Returns the module name of the class"""
@@ -204,3 +204,12 @@
 
     assert len(ids) == 1, "Ambiguous interface names: %s" % ids
     return ids[0]
+
+# BBB: Deprecated module; Will be gone in 3.3.
+from zope.deprecation import deprecated
+deprecated('Introspector',
+           'Use the public apidoc utilities. Will be gone in 3.3.')
+
+deprecated('interfaceToName',
+           'Use zope.app.component.interface.interfaceToName instead. '
+           'Will be gone in 3.3.')

Modified: Zope3/trunk/src/zope/app/introspector/browser.py
===================================================================
--- Zope3/trunk/src/zope/app/introspector/browser.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/introspector/browser.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -59,3 +59,8 @@
                     interface = getInterface(ob, interface)
                     directlyProvides(removeAllProxies(ob), directlyProvidedBy(ob)-interface)
 
+
+# BBB: Deprecated module; Will be gone in 3.3.
+from zope.deprecation import deprecated
+deprecated('IntrospectorView',
+           'Use the public apidoc utilities. Will be gone in 3.3.')

Modified: Zope3/trunk/src/zope/app/introspector/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/introspector/configure.zcml	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/introspector/configure.zcml	2005-02-28 13:42:02 UTC (rev 29341)
@@ -13,7 +13,8 @@
       "
       />
 
-
+<!-- BBB: Deprecated -->
+<!--
   <adapter
       for='*'
       factory="zope.app.introspector.Introspector"
@@ -22,17 +23,6 @@
       />
 
 
-  <!-- Browser directives -->
-
-  <!--browser:page
-      name="classBrowser.html"
-      for = "zope.interface.Interface"
-      permission="zope.ManageServices"
-      template="introspector.pt"
-      class="zope.app.introspector.browser.IntrospectorView"
-      menu="zmi_views" title="Introspector"
-      /-->
-
   <browser:pages
       for="zope.interface.Interface"
       permission="zope.app.introspector.Introspect"
@@ -57,5 +47,6 @@
       template="introspector.pt"
       class="zope.app.introspector.browser.IntrospectorView"
       />
+-->
 
 </configure>

Modified: Zope3/trunk/src/zope/app/introspector/tests/test_introspector.py
===================================================================
--- Zope3/trunk/src/zope/app/introspector/tests/test_introspector.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/introspector/tests/test_introspector.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -15,9 +15,13 @@
 
 $Id$
 """
+import zope.deprecation
+
 from unittest import TestCase, TestSuite, main, makeSuite
+zope.deprecation.__show__.off()
 from zope.app.introspector import Introspector
 from zope.app.introspector.interfaces import IIntrospector
+zope.deprecation.__show__.on()
 from zope.interface import Interface, Attribute, implements, directlyProvides
 from zope.interface.verify import verifyObject
 from zope.app.component.interface import provideInterface
@@ -90,7 +94,9 @@
     def test_setRequest(self):
         ints = Introspector(Interface)
         request = {'PATH_INFO': '++module++zope.app.introspector.Introspector'}
+        zope.deprecation.__show__.off()
         ints.setRequest(request)
+        zope.deprecation.__show__.on()
         self.assertEqual(ints.currentclass, Introspector)
 
     def test_getClass(self):

Modified: Zope3/trunk/src/zope/app/introspector/tests/test_introspectorview.py
===================================================================
--- Zope3/trunk/src/zope/app/introspector/tests/test_introspectorview.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/introspector/tests/test_introspectorview.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -15,16 +15,21 @@
 
 $Id$
 """
+import unittest
 
-import unittest
+import zope.deprecation
+
 from zope.app.component.testing import PlacefulSetup
 from zope.publisher.browser import TestRequest
 from zope.interface import Interface, directlyProvidedBy
 from zope.interface import directlyProvides, implements
 from zope.app.component.interface import provideInterface
 from zope.app.testing import ztapi, setup
+zope.deprecation.__show__.off()
 from zope.app.introspector.interfaces import IIntrospector
 from zope.app.introspector import Introspector
+from zope.app.introspector.browser import IntrospectorView
+zope.deprecation.__show__.on()
 
 class I1(Interface):
     pass
@@ -48,7 +53,6 @@
 
 
     def test_getInterfaceURL(self):
-        from zope.app.introspector.browser import IntrospectorView
 
         request = TestRequest()
         view = IntrospectorView(self.rootFolder, request)
@@ -62,7 +66,6 @@
                          '')
 
     def test_update(self):
-        from zope.app.introspector.browser import IntrospectorView
 
         class Context(object):
             implements(Interface)
@@ -76,7 +79,7 @@
         view.update()
         self.assert_(I1 in directlyProvidedBy(context))
         self.assert_(I2 in directlyProvidedBy(context))
-
+        
         context = Context()
         directlyProvides(context, I1)
         request = TestRequest()

Modified: Zope3/trunk/src/zope/app/workflow/stateful/browser/contentworkflow.py
===================================================================
--- Zope3/trunk/src/zope/app/workflow/stateful/browser/contentworkflow.py	2005-02-28 10:51:27 UTC (rev 29340)
+++ Zope3/trunk/src/zope/app/workflow/stateful/browser/contentworkflow.py	2005-02-28 13:42:02 UTC (rev 29341)
@@ -16,8 +16,7 @@
 $Id$
 """
 from zope.app import zapi
-from zope.app.introspector import interfaceToName
-from zope.app.component.interface import nameToInterface
+from zope.app.component.interface import nameToInterface, interfaceToName
 from zope.app.i18n import ZopeMessageIDFactory as _
 from zope.app.form.utility import setUpWidgets
 from zope.app.form.interfaces import IInputWidget



More information about the Zope3-Checkins mailing list