[Zope3-checkins] SVN: Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/ added test browser functional doctest to implement the feature (much easier to iterate here)

Tarek Ziadé tziade at nuxeo.com
Sat Oct 8 10:33:59 EDT 2005


Log message for revision 38952:
  added test browser functional doctest to implement the feature (much easier to iterate here)

Changed:
  U   Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/README.txt
  U   Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/configure.zcml
  A   Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/ftests.py
  U   Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/xmlrpcintrospection.py

-=-
Modified: Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/README.txt
===================================================================
--- Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/README.txt	2005-10-08 14:18:02 UTC (rev 38951)
+++ Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/README.txt	2005-10-08 14:33:59 UTC (rev 38952)
@@ -15,4 +15,131 @@
 
     - `methodSignature(method_name)`: Returns the method documentation of the given method.
 
-It is based on introspection mechanisms provided by the apidoc package.
\ No newline at end of file
+It is based on introspection mechanisms provided by the apidoc package.
+
+***** xmlrpc reminder *****
+
+Let's write a view that returns a folder listing:
+
+  >>> class FolderListing:
+  ...     def contents(self):
+  ...         return list(self.context.keys())
+
+Now we'll register it as a view:
+
+  >>> from zope.configuration import xmlconfig
+  >>> ignored = xmlconfig.string("""
+  ... <configure
+  ...     xmlns="http://namespaces.zope.org/zope"
+  ...     xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc"
+  ...     >
+  ...   <!-- We only need to do this include in this example,
+  ...        Normally the include has already been done for us. -->
+  ...   <include package="zope.app.publisher.xmlrpc" file="meta.zcml" />
+  ...
+  ...   <xmlrpc:view
+  ...       for="zope.app.folder.folder.IFolder"
+  ...       methods="contents"
+  ...       class="zope.app.xmlrpcintrospection.README.FolderListing"
+  ...       permission="zope.ManageContent"
+  ...       />
+  ... </configure>
+  ... """)
+
+Now, we'll add some items to the root folder:
+
+  >>> print http(r"""
+  ... POST /@@contents.html HTTP/1.1
+  ... Authorization: Basic bWdyOm1ncnB3
+  ... Content-Length: 73
+  ... Content-Type: application/x-www-form-urlencoded
+  ...
+  ... type_name=BrowserAdd__zope.app.folder.folder.Folder&new_value=f1""")
+  HTTP/1.1 303 See Other
+  ...
+
+  >>> print http(r"""
+  ... POST /@@contents.html HTTP/1.1
+  ... Authorization: Basic bWdyOm1ncnB3
+  ... Content-Length: 73
+  ... Content-Type: application/x-www-form-urlencoded
+  ...
+  ... type_name=BrowserAdd__zope.app.folder.folder.Folder&new_value=f2""")
+  HTTP/1.1 303 See Other
+  ...
+
+And call our xmlrpc method:
+
+  >>> print http(r"""
+  ... POST / HTTP/1.0
+  ... Authorization: Basic bWdyOm1ncnB3
+  ... Content-Length: 102
+  ... Content-Type: text/xml
+  ...
+  ... <?xml version='1.0'?>
+  ... <methodCall>
+  ... <methodName>contents</methodName>
+  ... <params>
+  ... </params>
+  ... </methodCall>
+  ... """)
+  HTTP/1.0 200 Ok
+  Content-Length: 208
+  Content-Type: text/xml;charset=utf-8
+  <BLANKLINE>
+  <?xml version='1.0'?>
+  <methodResponse>
+  <params>
+  <param>
+  <value><array><data>
+  <value><string>f1</string></value>
+  <value><string>f2</string></value>
+  </data></array></value>
+  </param>
+  </params>
+  </methodResponse>
+  <BLANKLINE>
+
+***** end of xmlrpc reminder *****
+
+Now we want to provide to that view introspection.
+Let's add three new xmlrcp methods, that published
+the introspection api.
+
+  >>> ignored = xmlconfig.string("""
+  ... <configure
+  ...     xmlns="http://namespaces.zope.org/zope"
+  ...     xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc"
+  ...     >
+  ...   <!-- We only need to do this include in this example,
+  ...        Normally the include has already been done for us. -->
+  ...   <include package="zope.app.publisher.xmlrpc" file="meta.zcml" />
+  ...   <xmlrpc:view
+  ...     for="zope.interface.Interface"
+  ...     methods="listAllMethods methodHelp methodSignature"
+  ...     class="zope.app.xmlrpcintrospection.xmlrpcintrospection.XMLRPCIntrospection"
+  ...     />
+  ... </configure>
+  ... """)
+
+They are linked to XMLRPCIntrospection class, that actually
+ knows how to lookup to all interfaces
+
+And call our xmlrpc method:
+
+  >>> print http(r"""
+  ... POST / HTTP/1.0
+  ... Authorization: Basic bWdyOm1ncnB3
+  ... Content-Length: 102
+  ... Content-Type: text/xml
+  ...
+  ... <?xml version='1.0'?>
+  ... <methodCall>
+  ... <methodName>listAllMethods</methodName>
+  ... <params>
+  ... </params>
+  ... </methodCall>
+  ... """)
+  'in process'
+
+

Modified: Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/configure.zcml
===================================================================
--- Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/configure.zcml	2005-10-08 14:18:02 UTC (rev 38951)
+++ Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/configure.zcml	2005-10-08 14:33:59 UTC (rev 38952)
@@ -4,9 +4,9 @@
   i18n_domain="zope">
 
   <xmlrpc:view
-      for="zope.interfaces.interfaces.IInterface"
+      for="zope.interface.interfaces.IInterface"
       methods="listAllMethods methodHelp methodSignature"
-      class=".xmlintrospection.XMLRPCIntrospection"
+      class="zope.app.xmlrpcintrospection.xmlrpcintrospection.XMLRPCIntrospection"
       />
 
 </configure>

Added: Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/ftests.py
===================================================================
--- Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/ftests.py	2005-10-08 14:18:02 UTC (rev 38951)
+++ Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/ftests.py	2005-10-08 14:33:59 UTC (rev 38952)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Functional tests for xmlrpcintrospection
+
+$Id:$
+"""
+import zope.interface
+import zope.app.folder.folder
+import zope.publisher.interfaces.xmlrpc
+from zope.app.testing import ztapi, functional, setup
+
+def setUp(test):
+    setup.setUpTestAsModule(test, 'zope.app.xmlrpcintrospection.README')
+
+def tearDown(test):
+    # clean up the views we registered:
+
+    # we use the fact that registering None unregisters whatever is
+    # registered. We can't use an unregistration call because that
+    # requires the object that was registered and we don't have that handy.
+    # (OK, we could get it if we want. Maybe later.)
+
+    ztapi.provideView(zope.app.folder.folder.IFolder,
+                        zope.publisher.interfaces.xmlrpc.IXMLRPCRequest,
+                        zope.interface,
+                        'contents',
+                        None,
+                        )
+    ztapi.provideView(zope.app.folder.folder.IFolder,
+                        zope.publisher.interfaces.xmlrpc.IXMLRPCRequest,
+                        zope.interface,
+                        'contents',
+                        None,
+                        )
+
+    setup.tearDownTestAsModule(test)
+
+def test_suite():
+    return functional.FunctionalDocFileSuite(
+        'README.txt', setUp=setUp, tearDown=tearDown)
+
+if __name__ == '__main__':
+    import unittest
+    unittest.main(defaultTest='test_suite')

Modified: Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/xmlrpcintrospection.py
===================================================================
--- Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/xmlrpcintrospection.py	2005-10-08 14:18:02 UTC (rev 38951)
+++ Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/xmlrpcintrospection.py	2005-10-08 14:33:59 UTC (rev 38952)
@@ -17,10 +17,26 @@
 """
 __docformat__ = 'restructuredtext'
 
+from zope.interface import providedBy
+from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
 from zope.app.publisher.xmlrpc import XMLRPCView
+from zope.app.apidoc.presentation import getViews, filterViewRegistrations,\
+                                         SPECIFIC_INTERFACE_LEVEL
 
 class XMLRPCIntrospection(XMLRPCView):
 
+    def _getXMLRPCViews(self):
+        adapter_registrations = []
+        interfaces = list(providedBy(self.context))
+
+        for interface in interfaces:
+            registrations = list(getView(interface, IXMLRPCRequest))
+            results = filterViewRegistrations(registrations,IXMLRPCRequest,
+                                              level=SPECIFIC_INTERFACE_LEVEL)
+            adapter_registrations.append(list(results))
+
+        return adapter_registrations
+
     def listAllMethods(self):
         return []
 



More information about the Zope3-Checkins mailing list