From eefef283d5ae280efa7c0967bb06756515ec3ede Mon Sep 17 00:00:00 2001 From: Steffen Allner Date: Tue, 12 May 2020 14:01:41 +0200 Subject: [PATCH] Support more `ServerProxy` options. (#10) `use_builtin_types` is in particular handy for the migration to Python 3 as it returns a `xmlrpc.client.Binary` instead of bytes. This class is not present in Python 2. Co-authored-by: Jason Madden Co-authored-by: Michael Howitz --- CHANGES.rst | 3 ++- src/zope/app/publisher/xmlrpc/testing.py | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0aa9dc4..33a41aa 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,8 @@ 4.3.0 (unreleased) ================== -- Nothing changed yet. +- Support options *use_datetime* (Python >= 2.7) and *use_builtin_types* + (`Python >= 3.5`) in ``.xmlrpc.testing.ServerProxy``. 4.2.0 (2019-12-05) diff --git a/src/zope/app/publisher/xmlrpc/testing.py b/src/zope/app/publisher/xmlrpc/testing.py index 0fba24a..c8760b2 100644 --- a/src/zope/app/publisher/xmlrpc/testing.py +++ b/src/zope/app/publisher/xmlrpc/testing.py @@ -1,11 +1,11 @@ try: import xmlrpclib -except ImportError: +except ImportError: # PY3 import xmlrpc.client as xmlrpclib try: import httplib -except ImportError: +except ImportError: # PY3 import http.client as httplib from io import BytesIO @@ -87,12 +87,18 @@ def request(self, host, handler, request_body, verbose=0): def ServerProxy(wsgi_app, uri, transport=None, encoding=None, - verbose=0, allow_none=0, handleErrors=True): - """A factory that creates a server proxy using the ZopeTestTransport - by default. + verbose=0, allow_none=0, handleErrors=True, + **transport_options): + """A factory that creates a server proxy. + + If ``transport`` is ``None`` use the ``ZopeTestTransport``, it gets + initialized with ``**transport_options``. Which options are supported + depends on the used Python version, see + ``xmlrpc.client.Transport.__init__`` resp. ``xmlrpclib.Transport.__init__`` + for details. """ if transport is None: - transport = ZopeTestTransport() + transport = ZopeTestTransport(**transport_options) transport.wsgi_app = wsgi_app if isinstance(transport, ZopeTestTransport): transport.handleErrors = handleErrors