Skip to content

Commit

Permalink
Fix XMLRPC with unicode characters
Browse files Browse the repository at this point in the history
  • Loading branch information
evanunderscore committed Dec 26, 2016
1 parent 1c66ea8 commit 99e7a7c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion supervisor/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 3 additions & 1 deletion supervisor/medusa/asynchat_25.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion supervisor/medusa/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions supervisor/tests/test_xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand Down
3 changes: 2 additions & 1 deletion supervisor/xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 99e7a7c

Please sign in to comment.