Skip to content

Commit c398f43

Browse files
committed
Set CGI default encoding to UTF-8 (like in XML-RPC)
1 parent 7514f08 commit c398f43

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

jsonrpclib/SimpleJSONRPCServer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,15 @@ class CGIJSONRPCRequestHandler(SimpleJSONRPCDispatcher, CGIXMLRPCRequestHandler)
594594
"""
595595
JSON-RPC CGI handler (and dispatcher)
596596
"""
597-
def __init__(self, encoding=None, config=jsonrpclib.config.DEFAULT):
597+
def __init__(self, encoding="UTF-8", config=jsonrpclib.config.DEFAULT):
598598
"""
599599
Sets up the dispatcher
600600
601601
:param encoding: Dispatcher encoding
602602
:param config: A JSONRPClib Config instance
603603
"""
604604
SimpleJSONRPCDispatcher.__init__(self, encoding, config)
605-
CGIXMLRPCRequestHandler.__init__(self)
605+
CGIXMLRPCRequestHandler.__init__(self, encoding=encoding)
606606

607607
def handle_jsonrpc(self, request_text):
608608
"""
@@ -614,10 +614,12 @@ def handle_jsonrpc(self, request_text):
614614
writer = sys.stdout
615615

616616
response = self._marshaled_dispatch(request_text)
617-
print('Content-Type: {0}'.format(self.json_config.content_type))
618-
print('Content-Length: {0:d}'.format(len(response)))
617+
response = response.encode(self.encoding)
618+
print("Content-Type:", self.json_config.content_type)
619+
print("Content-Length:", len(response))
619620
print()
620-
writer.write(response.encode(self.encoding))
621+
sys.stdout.flush()
622+
writer.write(response)
621623
writer.flush()
622624

623625
# XML-RPC alias

0 commit comments

Comments
 (0)