[Patch #893642] Add optional allow_none argument to SimpleXMLRPCServer, CGIXMLRPCRequestHandler

This commit is contained in:
Andrew M. Kuchling 2005-12-04 16:34:40 +00:00
parent bc6a195344
commit 10a16dea74
3 changed files with 16 additions and 8 deletions

View file

@ -13,7 +13,8 @@ be free standing, using \class{SimpleXMLRPCServer}, or embedded in a
CGI environment, using \class{CGIXMLRPCRequestHandler}. CGI environment, using \class{CGIXMLRPCRequestHandler}.
\begin{classdesc}{SimpleXMLRPCServer}{addr\optional{, \begin{classdesc}{SimpleXMLRPCServer}{addr\optional{,
requestHandler\optional{, logRequests}}} requestHandler\optional{,
logRequests\optional{allow_none}}}}
Create a new server instance. The \var{requestHandler} parameter Create a new server instance. 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
@ -24,11 +25,13 @@ CGI environment, using \class{CGIXMLRPCRequestHandler}.
setting this parameter to false will turn off logging. This class setting this parameter to false will turn off logging. This class
provides methods for registration of functions that can be called by provides methods for registration of functions that can be called by
the XML-RPC protocol. the XML-RPC protocol.
\versionchanged[The \var{allow_none} parameter was added]{2.5}
\end{classdesc} \end{classdesc}
\begin{classdesc}{CGIXMLRPCRequestHandler}{} \begin{classdesc}{CGIXMLRPCRequestHandler}{\optional{allow_none}}
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. \versionadded{2.3}
\versionchanged[The \var{allow_none} parameter was added]{2.5}
\end{classdesc} \end{classdesc}
\begin{classdesc}{SimpleXMLRPCRequestHandler}{} \begin{classdesc}{SimpleXMLRPCRequestHandler}{}

View file

@ -159,9 +159,10 @@ class SimpleXMLRPCDispatcher:
reason to instantiate this class directly. reason to instantiate this class directly.
""" """
def __init__(self): def __init__(self, allow_none):
self.funcs = {} self.funcs = {}
self.instance = None self.instance = None
self.allow_none = allow_none
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.
@ -251,7 +252,8 @@ class SimpleXMLRPCDispatcher:
response = self._dispatch(method, params) response = self._dispatch(method, params)
# 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)
except Fault, fault: except Fault, fault:
response = xmlrpclib.dumps(fault) response = xmlrpclib.dumps(fault)
except: except:
@ -479,10 +481,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=1): logRequests=1, allow_none=False):
self.logRequests = logRequests self.logRequests = logRequests
SimpleXMLRPCDispatcher.__init__(self) SimpleXMLRPCDispatcher.__init__(self, allow_none)
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
@ -496,8 +498,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): def __init__(self, allow_none=False):
SimpleXMLRPCDispatcher.__init__(self) SimpleXMLRPCDispatcher.__init__(self, allow_none)
def handle_xmlrpc(self, request_text): def handle_xmlrpc(self, request_text):
"""Handle a single XML-RPC request""" """Handle a single XML-RPC request"""

View file

@ -454,6 +454,9 @@ 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
SimpleXMLRPCServer and CGIXMLRPCRequestHandler.
- Bug #1110478: Revert os.environ.update to do putenv again. - Bug #1110478: Revert os.environ.update to do putenv again.
- Bug #1103844: fix distutils.install.dump_dirs() with negated options. - Bug #1103844: fix distutils.install.dump_dirs() with negated options.