From 99e7a7c2e47e36004b9841b28b4b6fd4018bae82 Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 26 Dec 2016 19:55:55 +1100 Subject: [PATCH] Fix XMLRPC with unicode characters --- supervisor/http.py | 4 +++- supervisor/medusa/asynchat_25.py | 4 +++- supervisor/medusa/http_server.py | 3 ++- supervisor/tests/test_xmlrpc.py | 4 ++-- supervisor/xmlrpc.py | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/supervisor/http.py b/supervisor/http.py index 2e260cdcf..02bb9310e 100644 --- a/supervisor/http.py +++ b/supervisor/http.py @@ -371,10 +371,12 @@ def refill_buffer (self): self.producer_fifo.pop() self.close() return - elif isinstance(p, str): + elif isinstance(p, bytes): self.producer_fifo.pop() self.ac_out_buffer += p return + else: + assert not isinstance(p, str) data = p.more() diff --git a/supervisor/medusa/asynchat_25.py b/supervisor/medusa/asynchat_25.py index bb8976d05..59d54012a 100644 --- a/supervisor/medusa/asynchat_25.py +++ b/supervisor/medusa/asynchat_25.py @@ -194,10 +194,12 @@ def refill_buffer (self): self.producer_fifo.pop() self.close() return - elif isinstance(p, str): + elif isinstance(p, bytes): self.producer_fifo.pop() self.ac_out_buffer += p return + else: + assert not isinstance(p, str) data = p.more() if data: self.ac_out_buffer = self.ac_out_buffer + data diff --git a/supervisor/medusa/http_server.py b/supervisor/medusa/http_server.py index b036a429c..050b9dfb0 100644 --- a/supervisor/medusa/http_server.py +++ b/supervisor/medusa/http_server.py @@ -260,10 +260,11 @@ def found_terminator (self): ) def push (self, thing): - if type(thing) == type(''): + if isinstance(thing, bytes): self.outgoing.append(producers.simple_producer(thing, buffer_size=len(thing))) else: + assert not isinstance(thing, str) self.outgoing.append(thing) def response (self, code=200): diff --git a/supervisor/tests/test_xmlrpc.py b/supervisor/tests/test_xmlrpc.py index e30b4d7a2..2b4da32a0 100644 --- a/supervisor/tests/test_xmlrpc.py +++ b/supervisor/tests/test_xmlrpc.py @@ -413,7 +413,7 @@ def getconn(): self.assertEqual(dummy_conn.closed, True) self.assertEqual(dummy_conn.requestargs[0], 'POST') self.assertEqual(dummy_conn.requestargs[1], '/') - self.assertEqual(dummy_conn.requestargs[2], '') + self.assertEqual(dummy_conn.requestargs[2], b'') self.assertEqual(dummy_conn.requestargs[3]['Content-Length'], '0') self.assertEqual(dummy_conn.requestargs[3]['Content-Type'], 'text/xml') self.assertEqual(dummy_conn.requestargs[3]['Authorization'], @@ -439,7 +439,7 @@ def getconn(): self.assertEqual(dummy_conn.closed, False) self.assertEqual(dummy_conn.requestargs[0], 'POST') self.assertEqual(dummy_conn.requestargs[1], '/') - self.assertEqual(dummy_conn.requestargs[2], '') + self.assertEqual(dummy_conn.requestargs[2], b'') self.assertEqual(dummy_conn.requestargs[3]['Content-Length'], '0') self.assertEqual(dummy_conn.requestargs[3]['Content-Type'], 'text/xml') self.assertEqual(dummy_conn.requestargs[3]['Authorization'], diff --git a/supervisor/xmlrpc.py b/supervisor/xmlrpc.py index 1c9f43fd1..17e25d043 100644 --- a/supervisor/xmlrpc.py +++ b/supervisor/xmlrpc.py @@ -427,7 +427,7 @@ def continue_request(self, data, request): # if we get anything but a function, it implies that this # response doesn't need to be deferred, we can service it # right away. - body = xmlrpc_marshal(value) + body = as_bytes(xmlrpc_marshal(value)) request['Content-Type'] = 'text/xml' request['Content-Length'] = len(body) request.push(body) @@ -499,6 +499,7 @@ def get_connection(serverurl=serverurl): raise ValueError('Unknown protocol for serverurl %s' % serverurl) def request(self, host, handler, request_body, verbose=0): + request_body = as_bytes(request_body) if not self.connection: self.connection = self._get_connection() self.headers = {