[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/XMLRPC - IXMLRPCPublisher.py:1.2 MethodPublisher.py:1.2 XMLRPCRequest.py:1.2 XMLRPCResponse.py:1.2 __init__.py:1.2 metaConfigure.py:1.2 xmlrpc-meta.zcml:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:30:05 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/XMLRPC
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/Publisher/XMLRPC

Added Files:
	IXMLRPCPublisher.py MethodPublisher.py XMLRPCRequest.py 
	XMLRPCResponse.py __init__.py metaConfigure.py 
	xmlrpc-meta.zcml 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.

=== Zope3/lib/python/Zope/Publisher/XMLRPC/IXMLRPCPublisher.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+from Zope.Publisher.HTTP.IHTTPPublisher import IHTTPPublisher
+
+
+class IXMLRPCPublisher(IHTTPPublisher):
+    """This is identical to the regular HTTP version.
+
+       This interface is used as marker.
+    """
+


=== Zope3/lib/python/Zope/Publisher/XMLRPC/MethodPublisher.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+from IXMLRPCPublisher import IXMLRPCPublisher
+from Zope.Publisher.HTTP.DefaultPublisher import DefaultPublisher
+
+class MethodPublisher(DefaultPublisher):
+    """Simple XML-RPC publisher that is identical to the HTTP Default Publisher
+       except that it implements the IXMLRPCPublisher interface. 
+    """
+
+    __implements__ = IXMLRPCPublisher


=== Zope3/lib/python/Zope/Publisher/XMLRPC/XMLRPCRequest.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+import xmlrpclib
+from cgi import FieldStorage
+from Zope.Publisher.HTTP.HTTPRequest import HTTPRequest
+from IXMLRPCPublisher import IXMLRPCPublisher
+
+from XMLRPCResponse import XMLRPCResponse
+
+class XMLRPCRequest(HTTPRequest):
+
+    __implements__ = HTTPRequest.__implements__
+
+    # _presentation_type is overridden from the BaseRequest 
+    # to implement IXMLRPCPublisher
+    _presentation_type = IXMLRPCPublisher
+
+
+    _args = ()
+
+
+    def _createResponse(self, outstream):
+        """Create a specific XML-RPC response object."""
+        return XMLRPCResponse(outstream)
+
+    
+    ######################################
+    # from: Zope.Publisher.IPublisherRequest.IPublisherRequest
+
+    def processInputs(self):
+        'See Zope.Publisher.IPublisherRequest.IPublisherRequest'
+
+        # Parse the request XML structure
+        self._args, function = xmlrpclib.loads(self._body_instream.read())
+        # Translate '.' to '/' in function to represent object traversal.
+        function = function.replace('.', '/')
+
+        if function:
+            self.setPathSuffix((function,))
+
+
+
+class TestRequest(XMLRPCRequest):
+
+    def __init__(self, body_instream=None, outstream=None, environ=None,
+                 response=None, **kw):
+
+        _testEnv =  {
+            'SERVER_URL':         'http://127.0.0.1',
+            'HTTP_HOST':          '127.0.0.1',
+            'CONTENT_LENGTH':     '0',
+            'GATEWAY_INTERFACE':  'TestFooInterface/1.0',
+            }
+
+        if environ:
+            _testEnv.update(environ)
+        if kw:
+            _testEnv.update(kw)
+        if body_instream is None:
+            from StringIO import StringIO
+            body_instream = StringIO('')
+
+        if outstream is None:
+            outstream = StringIO()
+
+        super(TestRequest, self).__init__(
+            body_instream, outstream, _testEnv, response)
+


=== Zope3/lib/python/Zope/Publisher/XMLRPC/XMLRPCResponse.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+import sys
+import xmlrpclib
+from Zope.Publisher.HTTP.HTTPResponse import HTTPResponse
+from Zope.Publisher.Exceptions import Redirect
+
+
+class XMLRPCResponse(HTTPResponse):
+    """XMLRPC response
+    """
+
+    def setBody(self, body):
+        """Sets the body of the response
+        
+        Sets the return body equal to the (string) argument "body". Also
+        updates the "content-length" return header.
+
+        If the body is a 2-element tuple, then it will be treated
+        as (title,body)
+        
+        If is_error is true then the HTML will be formatted as a Zope error
+        message instead of a generic HTML page.
+        """
+        if isinstance(body, xmlrpclib.Fault):
+            # Convert Fault object to XML-RPC response.
+            body = xmlrpclib.dumps(body, methodresponse=1)
+        else:
+            # Marshall our body as an XML-RPC response. Strings will be sent
+            # strings, integers as integers, etc. We do *not* convert
+            # everything to a string first.
+            if body is None:
+                body = xmlrpclib.False # Argh, XML-RPC doesn't handle null
+            try:
+                body = xmlrpclib.dumps((body,), methodresponse=1)
+            except:
+                self.exception()
+                return
+        # Set our body to the XML-RPC message, and fix our MIME type.
+        self.setHeader('content-type', 'text/xml')
+
+        self._body = body
+        self._updateContentLength()
+
+
+    def handleException(self, exc_info):
+        """
+        """
+        t, value = exc_info[:2]
+
+        import traceback
+        traceback.print_tb(exc_info[2])
+        print t
+        print value
+
+        # Create an appropriate Fault object. Unfortunately, we throw away
+        # most of the debugging information. More useful error reporting is
+        # left as an exercise for the reader.
+        Fault = xmlrpclib.Fault
+        fault_text = None
+        try:
+            if isinstance(value, Fault):
+                fault_text = value
+            elif isinstance(value, Exception):
+                fault_text = Fault(-1, "Unexpected Zope exception: " +
+                                   str(value))
+            else:
+                fault_text = Fault(-2, "Unexpected Zope error value: " +
+                                   str(value))
+        except:
+            fault_text = Fault(-3, "Unknown Zope fault type")
+
+        # Do the damage.
+        self.setBody(fault_text)
+        self.setStatus(200)


=== Zope3/lib/python/Zope/Publisher/XMLRPC/__init__.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################


=== Zope3/lib/python/Zope/Publisher/XMLRPC/metaConfigure.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+from Zope.App.ComponentArchitecture.metaConfigure import view as _view
+    
+def view(_context, **__kw):
+    return _view(_context,
+                 type='Zope.Publisher.XMLRPC.IXMLRPCPublisher.',
+                 **__kw)


=== Zope3/lib/python/Zope/Publisher/XMLRPC/xmlrpc-meta.zcml 1.1 => 1.2 ===
+  
+  <!-- Zope.Publisher.XMLRPC -->
+  <directives namespace="http://namespaces.zope.org/xmlrpc">
+    <directive name="view" attributes="factory name for"
+       handler="Zope.Publisher.XMLRPC.metaConfigure.view" />
+  </directives>
+
+</zopeConfigure>