[Zope3-checkins] SVN: Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/ methodHelp implementation

Tarek Ziadé tziade at nuxeo.com
Sun Oct 9 06:50:47 EDT 2005


Log message for revision 38999:
  methodHelp implementation

Changed:
  U   Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/README.txt
  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-09 10:29:01 UTC (rev 38998)
+++ Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/README.txt	2005-10-09 10:50:47 UTC (rev 38999)
@@ -333,3 +333,84 @@
   </params>
   </methodResponse>
   <BLANKLINE>
+
+Last, but not least, the method help:
+
+  >>> class JacksonFiveRPCDocumented:
+  ...     @xmlrpccallable(str, str, str, str)
+  ...     def says(self, a, b, c):
+  ...         """ this is the help for
+  ...             says()
+  ...         """
+  ...         return '%s %s, %s, lalalala, you and me, lalalala' % (a, b, c)
+  ...     def says_not_documented(self, a, b, c):
+  ...         return '%s %s, %s, lalalala, you and me, lalalala' % (a, b, c)
+  >>> 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="says says_not_documented"
+  ...       class="zope.app.xmlrpcintrospection.README.JacksonFiveRPCDocumented"
+  ...       permission="zope.ManageContent"
+  ...       />
+  ... </configure>
+  ... """)
+  >>> print http(r"""
+  ... POST / HTTP/1.0
+  ... Content-Type: text/xml
+  ...
+  ... <?xml version='1.0'?>
+  ... <methodCall>
+  ... <methodName>methodHelp</methodName>
+  ... <params>
+  ... <param>
+  ... <value>says</value>
+  ... </params>
+  ... </methodCall>
+  ... """, handle_errors=False)
+  HTTP/1.0 200 Ok
+  ...
+  <?xml version='1.0'?>
+  <methodResponse>
+  <params>
+  <param>
+  <value><string> this is the help for
+               says()
+           </string></value>
+  </param>
+  </params>
+  </methodResponse>
+  <BLANKLINE>
+  >>> print http(r"""
+  ... POST / HTTP/1.0
+  ... Content-Type: text/xml
+  ...
+  ... <?xml version='1.0'?>
+  ... <methodCall>
+  ... <methodName>methodHelp</methodName>
+  ... <params>
+  ... <param>
+  ... <value>says_not_documented</value>
+  ... </params>
+  ... </methodCall>
+  ... """, handle_errors=False)
+  HTTP/1.0 200 Ok
+  ...
+  <?xml version='1.0'?>
+  <methodResponse>
+  <params>
+  <param>
+  <value><string>undef</string></value>
+  </param>
+  </params>
+  </methodResponse>
+  <BLANKLINE>
+

Modified: Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/xmlrpcintrospection.py
===================================================================
--- Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/xmlrpcintrospection.py	2005-10-09 10:29:01 UTC (rev 38998)
+++ Zope3/branches/tziade_xmlintrospection/src/zope/app/xmlrpcintrospection/xmlrpcintrospection.py	2005-10-09 10:50:47 UTC (rev 38999)
@@ -47,6 +47,10 @@
         """ returns the method signature """
         return self._getXMLRPCMethodSignature(method_name)
 
+    def methodHelp(self, method_name):
+        """ returns the docstring of the method """
+        return self._getXMLRPCMethodHelp(method_name)
+
     def __call__(self, *args, **kw):
         return self.listAllMethods()
 
@@ -106,6 +110,12 @@
         # XXX: if defaults are given, we can render their type
         return [['undef'] * (self._getFunctionArgumentSize(func) + 1)]
 
+    def _getFunctionHelp(self, func):
+        if hasattr(func, '__doc__') and func.__doc__ is not None:
+            if func.__doc__.strip() != '':
+                return func.__doc__
+        return 'undef'
+
     #
     # Lookup APIS
     #
@@ -134,6 +144,17 @@
             if result.name == method_name:
                 method = getattr(result.value, method_name)
                 return self._getFunctionSignature(method)
-        # XXX see RFC here, if we want to raise or no
-        return None
 
+        return 'undef'
+
+    def _getXMLRPCMethodHelp(self, method_name):
+        """ The help of a method is just the doctstring, if given
+        """
+        interfaces = list(providedBy(self.context))
+
+        for result in self._getRegistrationAdapters(interfaces):
+            if result.name == method_name:
+                method = getattr(result.value, method_name)
+                return self._getFunctionHelp(method)
+
+        return 'undef'



More information about the Zope3-Checkins mailing list