[Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
This commit is contained in:
parent
ce100d8d4c
commit
427aedbbd4
|
@ -14,24 +14,31 @@ CGI environment, using \class{CGIXMLRPCRequestHandler}.
|
||||||
|
|
||||||
\begin{classdesc}{SimpleXMLRPCServer}{addr\optional{,
|
\begin{classdesc}{SimpleXMLRPCServer}{addr\optional{,
|
||||||
requestHandler\optional{,
|
requestHandler\optional{,
|
||||||
logRequests\optional{allow_none}}}}
|
logRequests\optional{allow_none\optional{, encoding}}}}}
|
||||||
|
|
||||||
Create a new server instance. The \var{requestHandler} parameter
|
Create a new server instance. This class
|
||||||
|
provides methods for registration of functions that can be called by
|
||||||
|
the XML-RPC protocol. The \var{requestHandler} parameter
|
||||||
should be a factory for request handler instances; it defaults to
|
should be a factory for request handler instances; it defaults to
|
||||||
\class{SimpleXMLRPCRequestHandler}. The \var{addr} and
|
\class{SimpleXMLRPCRequestHandler}. The \var{addr} and
|
||||||
\var{requestHandler} parameters are passed to the
|
\var{requestHandler} parameters are passed to the
|
||||||
\class{\refmodule{SocketServer}.TCPServer} constructor. If
|
\class{\refmodule{SocketServer}.TCPServer} constructor. If
|
||||||
\var{logRequests} is true (the default), requests will be logged;
|
\var{logRequests} is true (the default), requests will be logged;
|
||||||
setting this parameter to false will turn off logging. This class
|
setting this parameter to false will turn off logging.
|
||||||
provides methods for registration of functions that can be called by
|
The \var{allow_none} and \var{encoding} parameters are passed on to
|
||||||
the XML-RPC protocol.
|
\module{xmlrpclib} and control the XML-RPC responses that will be returned
|
||||||
\versionchanged[The \var{allow_none} parameter was added]{2.5}
|
from the server.
|
||||||
|
\versionchanged[The \var{allow_none} and \var{encoding} parameters were added]{2.5}
|
||||||
\end{classdesc}
|
\end{classdesc}
|
||||||
|
|
||||||
\begin{classdesc}{CGIXMLRPCRequestHandler}{\optional{allow_none}}
|
\begin{classdesc}{CGIXMLRPCRequestHandler}{\optional{allow_none\optional{, encoding}}}
|
||||||
Create a new instance to handle XML-RPC requests in a CGI
|
Create a new instance to handle XML-RPC requests in a CGI
|
||||||
environment. \versionadded{2.3}
|
environment.
|
||||||
\versionchanged[The \var{allow_none} parameter was added]{2.5}
|
The \var{allow_none} and \var{encoding} parameters are passed on to
|
||||||
|
\module{xmlrpclib} and control the XML-RPC responses that will be returned
|
||||||
|
from the server.
|
||||||
|
\versionadded{2.3}
|
||||||
|
\versionchanged[The \var{allow_none} and \var{encoding} parameters were added]{2.5}
|
||||||
\end{classdesc}
|
\end{classdesc}
|
||||||
|
|
||||||
\begin{classdesc}{SimpleXMLRPCRequestHandler}{}
|
\begin{classdesc}{SimpleXMLRPCRequestHandler}{}
|
||||||
|
|
|
@ -159,10 +159,11 @@ class SimpleXMLRPCDispatcher:
|
||||||
reason to instantiate this class directly.
|
reason to instantiate this class directly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, allow_none):
|
def __init__(self, allow_none, encoding):
|
||||||
self.funcs = {}
|
self.funcs = {}
|
||||||
self.instance = None
|
self.instance = None
|
||||||
self.allow_none = allow_none
|
self.allow_none = allow_none
|
||||||
|
self.encoding = encoding
|
||||||
|
|
||||||
def register_instance(self, instance, allow_dotted_names=False):
|
def register_instance(self, instance, allow_dotted_names=False):
|
||||||
"""Registers an instance to respond to XML-RPC requests.
|
"""Registers an instance to respond to XML-RPC requests.
|
||||||
|
@ -253,13 +254,15 @@ class SimpleXMLRPCDispatcher:
|
||||||
# wrap response in a singleton tuple
|
# wrap response in a singleton tuple
|
||||||
response = (response,)
|
response = (response,)
|
||||||
response = xmlrpclib.dumps(response, methodresponse=1,
|
response = xmlrpclib.dumps(response, methodresponse=1,
|
||||||
allow_none = self.allow_none)
|
allow_none=self.allow_none, encoding=self.encoding)
|
||||||
except Fault, fault:
|
except Fault, fault:
|
||||||
response = xmlrpclib.dumps(fault)
|
response = xmlrpclib.dumps(fault, allow_none=self.allow_none,
|
||||||
|
encoding=self.encoding)
|
||||||
except:
|
except:
|
||||||
# report exception back to server
|
# report exception back to server
|
||||||
response = xmlrpclib.dumps(
|
response = xmlrpclib.dumps(
|
||||||
xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value))
|
xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value)),
|
||||||
|
encoding=self.encoding, allow_none=self.allow_none,
|
||||||
)
|
)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -481,10 +484,10 @@ class SimpleXMLRPCServer(SocketServer.TCPServer,
|
||||||
allow_reuse_address = True
|
allow_reuse_address = True
|
||||||
|
|
||||||
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
|
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
|
||||||
logRequests=True, allow_none=False):
|
logRequests=True, allow_none=False, encoding=None):
|
||||||
self.logRequests = logRequests
|
self.logRequests = logRequests
|
||||||
|
|
||||||
SimpleXMLRPCDispatcher.__init__(self, allow_none)
|
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
|
||||||
SocketServer.TCPServer.__init__(self, addr, requestHandler)
|
SocketServer.TCPServer.__init__(self, addr, requestHandler)
|
||||||
|
|
||||||
# [Bug #1222790] If possible, set close-on-exec flag; if a
|
# [Bug #1222790] If possible, set close-on-exec flag; if a
|
||||||
|
@ -498,8 +501,8 @@ class SimpleXMLRPCServer(SocketServer.TCPServer,
|
||||||
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
|
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
|
||||||
"""Simple handler for XML-RPC data passed through CGI."""
|
"""Simple handler for XML-RPC data passed through CGI."""
|
||||||
|
|
||||||
def __init__(self, allow_none=False):
|
def __init__(self, allow_none=False, encoding=None):
|
||||||
SimpleXMLRPCDispatcher.__init__(self, allow_none)
|
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
|
||||||
|
|
||||||
def handle_xmlrpc(self, request_text):
|
def handle_xmlrpc(self, request_text):
|
||||||
"""Handle a single XML-RPC request"""
|
"""Handle a single XML-RPC request"""
|
||||||
|
|
|
@ -454,7 +454,7 @@ Library
|
||||||
- Bug #792570: SimpleXMLRPCServer had problems if the request grew too large.
|
- Bug #792570: SimpleXMLRPCServer had problems if the request grew too large.
|
||||||
Fixed by reading the HTTP body in chunks instead of one big socket.read().
|
Fixed by reading the HTTP body in chunks instead of one big socket.read().
|
||||||
|
|
||||||
- Patch #893642: add allow_none argument to constructors of
|
- Patches #893642, #1039083: add allow_none, encoding arguments to constructors of
|
||||||
SimpleXMLRPCServer and CGIXMLRPCRequestHandler.
|
SimpleXMLRPCServer and CGIXMLRPCRequestHandler.
|
||||||
|
|
||||||
- Bug #1110478: Revert os.environ.update to do putenv again.
|
- Bug #1110478: Revert os.environ.update to do putenv again.
|
||||||
|
|
Loading…
Reference in New Issue