summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpc
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2009-04-01 20:20:43 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2009-04-01 20:20:43 (GMT)
commitb3af08f84c36106f8873d0fa7e8775aa0ef6ab75 (patch)
tree8a22b05e855f594fea848616e5e7556db06e0bde /Lib/xmlrpc
parentdf8709d7b141c334ebacbf0e4380de7fd90d1276 (diff)
downloadcpython-b3af08f84c36106f8873d0fa7e8775aa0ef6ab75.zip
cpython-b3af08f84c36106f8873d0fa7e8775aa0ef6ab75.tar.gz
cpython-b3af08f84c36106f8873d0fa7e8775aa0ef6ab75.tar.bz2
Fix for issue5040. Adding support for unicode message passing and tests for unicode message and test for Content-Length.
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r--Lib/xmlrpc/client.py4
-rw-r--r--Lib/xmlrpc/server.py27
2 files changed, 18 insertions, 13 deletions
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py
index 86988de..cc717e0 100644
--- a/Lib/xmlrpc/client.py
+++ b/Lib/xmlrpc/client.py
@@ -1316,7 +1316,7 @@ class ServerProxy:
transport = Transport(use_datetime=use_datetime)
self.__transport = transport
- self.__encoding = encoding
+ self.__encoding = encoding or 'utf-8'
self.__verbose = verbose
self.__allow_none = allow_none
@@ -1324,7 +1324,7 @@ class ServerProxy:
# call a method on the remote server
request = dumps(params, methodname, encoding=self.__encoding,
- allow_none=self.__allow_none)
+ allow_none=self.__allow_none).encode(self.__encoding)
response = self.__transport.request(
self.__host,
diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py
index ea828a5..f84176f 100644
--- a/Lib/xmlrpc/server.py
+++ b/Lib/xmlrpc/server.py
@@ -163,7 +163,7 @@ class SimpleXMLRPCDispatcher:
self.funcs = {}
self.instance = None
self.allow_none = allow_none
- self.encoding = encoding
+ self.encoding = encoding or 'utf-8'
def register_instance(self, instance, allow_dotted_names=False):
"""Registers an instance to respond to XML-RPC requests.
@@ -266,7 +266,7 @@ class SimpleXMLRPCDispatcher:
encoding=self.encoding, allow_none=self.allow_none,
)
- return response
+ return response.encode(self.encoding)
def system_listMethods(self):
"""system.listMethods() => ['add', 'subtract', 'multiple']
@@ -473,8 +473,6 @@ class SimpleXMLRPCRequestHandler(BaseHTTPRequestHandler):
self.end_headers()
else:
- # Got a valid XML RPC response; convert to bytes first
- response = response.encode("utf-8")
self.send_response(200)
self.send_header("Content-type", "text/xml")
self.send_header("Content-length", str(len(response)))
@@ -551,7 +549,9 @@ class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
print('Content-Type: text/xml')
print('Content-Length: %d' % len(response))
print()
- sys.stdout.write(response)
+ sys.stdout.flush()
+ sys.stdout.buffer.write(response)
+ sys.stdout.buffer.flush()
def handle_get(self):
"""Handle a single HTTP GET request.
@@ -569,11 +569,14 @@ class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
'message' : message,
'explain' : explain
}
+ response = response.encode('utf-8')
print('Status: %d %s' % (code, message))
- print('Content-Type: text/html')
+ print('Content-Type: %s' % http.server.DEFAULT_ERROR_CONTENT_TYPE)
print('Content-Length: %d' % len(response))
print()
- sys.stdout.write(response)
+ sys.stdout.flush()
+ sys.stdout.buffer.write(response)
+ sys.stdout.buffer.flush()
def handle_request(self, request_text = None):
"""Handle a single XML-RPC request passed through a CGI post method.
@@ -814,12 +817,12 @@ class DocXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
self.report_404()
return
- response = self.server.generate_html_documentation()
+ response = self.server.generate_html_documentation().encode('utf-8')
self.send_response(200)
self.send_header("Content-type", "text/html")
self.send_header("Content-length", str(len(response)))
self.end_headers()
- self.wfile.write(response.encode())
+ self.wfile.write(response)
# shut down the connection
self.wfile.flush()
@@ -852,12 +855,14 @@ class DocCGIXMLRPCRequestHandler( CGIXMLRPCRequestHandler,
documentation.
"""
- response = self.generate_html_documentation()
+ response = self.generate_html_documentation().encode('utf-8')
print('Content-Type: text/html')
print('Content-Length: %d' % len(response))
print()
- sys.stdout.write(response)
+ sys.stdout.flush()
+ sys.stdout.buffer.write(response)
+ sys.stdout.buffer.flush()
def __init__(self):
CGIXMLRPCRequestHandler.__init__(self)