Skip to content

Commit

Permalink
Implement changes suggested by @jamadden.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Jun 8, 2020
1 parent cf40294 commit 32cf1e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 5 additions & 8 deletions src/zope/app/publisher/xmlrpc/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ If you need to raise an error, the prefered way to do it is via an
... self.request = request
...
... def your_fault(self):
... return xmlrpclib.Fault(42, "It's your fault 😢!")
... return xmlrpclib.Fault(42, u"It's your fault \N{SNOWMAN}!")

Now we'll register it as a view:

Expand All @@ -271,21 +271,18 @@ Now, when we call it, we get a proper XML-RPC fault:

>>> try:
... from xmlrpc.client import Fault
... expected = '<Fault 42: "It\'s your fault 😢!">'
... expected = '<Fault 42: "It\'s your fault \N{SNOWMAN}!">'
... except ImportError: # PY2
... from xmlrpclib import Fault
... expected = '<Fault 42: u"It\'s your fault \U0001f622!">'
... expected = '<Fault 42: u"It\'s your fault \u2603!">'
>>> proxy = ServerProxy(wsgi_app, "http://mgr:mgrpw@localhost/")
>>> # When dropping PY2 we can come back here to asserting the text of the
>>> # exception:
>>> try:
... proxy.your_fault()
... except Fault as e:
... assert str(e) == expected, str(e)
... except Exception as e:
... raise AssertionError('Raised %s instead of `Fault`!')
... else:
... raise AssertionError('Nothing raised.')
... str(e) == expected
True


DateTime values
Expand Down
7 changes: 4 additions & 3 deletions src/zope/app/publisher/xmlrpc/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ def request(self, host, handler, request_body, verbose=0):
headers)

body = response.getBody()
if not isinstance(errmsg, bytes):
# Python 3
errmsg = errmsg.encode("ascii")
body = body if isinstance(body, bytes) else body.encode('latin-1')
errmsg = (errmsg
if isinstance(errmsg, bytes)
else errmsg.encode('ascii')) # HTTP response lines are ASCII
content = b'HTTP/1.0 ' + errmsg + b'\n\n' + body

res = httplib.HTTPResponse(FakeSocket(content))
Expand Down

0 comments on commit 32cf1e5

Please sign in to comment.