Skip to content

Commit

Permalink
Support more ServerProxy options.
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
sallner committed Apr 17, 2020
1 parent 19ee519 commit f5f8787
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Expand Up @@ -5,7 +5,7 @@
4.3.0 (unreleased)
==================

- Nothing changed yet.
- Support options `use_datetime` and `use_builtin_types` of ``ServerProxy``.


4.2.0 (2019-12-05)
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Expand Up @@ -111,7 +111,10 @@ def _read(fname):
],
extras_require={
'test': tests_require,
'testing': 'zope.app.wsgi',
'testing': [
'six',
'zope.app.wsgi',
]
},
tests_require=tests_require,
zip_safe=False,
Expand Down
10 changes: 8 additions & 2 deletions src/zope/app/publisher/xmlrpc/testing.py
Expand Up @@ -9,6 +9,7 @@
import http.client as httplib

from io import BytesIO
import six

from zope.app.wsgi.testlayer import http as _http

Expand Down Expand Up @@ -87,12 +88,17 @@ 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):
verbose=0, allow_none=0, handleErrors=True,
use_datetime=False, use_builtin_types=False):
"""A factory that creates a server proxy using the ZopeTestTransport
by default.
"""
transport_options = dict(use_datetime=use_datetime)
if six.PY3:
# use_builtin_types is only available since 3.3
transport_options['use_builtin_types'] = use_builtin_types
if transport is None:
transport = ZopeTestTransport()
transport = ZopeTestTransport(**transport_options)
transport.wsgi_app = wsgi_app
if isinstance(transport, ZopeTestTransport):
transport.handleErrors = handleErrors
Expand Down

0 comments on commit f5f8787

Please sign in to comment.