Skip to content

Commit 1afe294

Browse files
author
collin.winter
committed
Patch #1599845: Add an option to disable the implicit calls to server_bind() and server_activate() in the constructors for TCPServer, SimpleXMLRPCServer and DocXMLRPCServer.
git-svn-id: http://svn.python.org/projects/python/trunk@54262 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent c448072 commit 1afe294

6 files changed

Lines changed: 30 additions & 12 deletions

File tree

Doc/lib/libdocxmlrpc.tex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ \section{\module{DocXMLRPCServer} ---
1414
\class{DocXMLRPCServer}, or embedded in a CGI environment, using
1515
\class{DocCGIXMLRPCRequestHandler}.
1616

17-
\begin{classdesc}{DocXMLRPCServer}{addr\optional{,
18-
requestHandler\optional{, logRequests}}}
17+
\begin{classdesc}{DocXMLRPCServer}{addr\optional{,
18+
requestHandler\optional{,
19+
logRequests\optional{,
20+
allow_none\optional{,
21+
encoding\optional{,
22+
bind_and_activate}}}}}}
1923

2024
Create a new server instance. All parameters have the same meaning as
2125
for \class{SimpleXMLRPCServer.SimpleXMLRPCServer};

Doc/lib/libsimplexmlrpc.tex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ \section{\module{SimpleXMLRPCServer} ---
1515

1616
\begin{classdesc}{SimpleXMLRPCServer}{addr\optional{,
1717
requestHandler\optional{,
18-
logRequests\optional{, allow_none\optional{, encoding}}}}}
18+
logRequests\optional{,
19+
allow_none\optional{,
20+
encoding}}}}}
1921

2022
Create a new server instance. This class
2123
provides methods for registration of functions that can be called by
@@ -28,8 +30,13 @@ \section{\module{SimpleXMLRPCServer} ---
2830
setting this parameter to false will turn off logging.
2931
The \var{allow_none} and \var{encoding} parameters are passed on to
3032
\module{xmlrpclib} and control the XML-RPC responses that will be returned
31-
from the server.
33+
from the server. The \var{bind_and_activate} parameter controls whether
34+
\method{server_bind()} and \method{server_activate()} are called immediately
35+
by the constructor; it defaults to true. Setting it to false allows code to
36+
manipulate the \var{allow_reuse_address} class variable before the address
37+
is bound.
3238
\versionchanged[The \var{allow_none} and \var{encoding} parameters were added]{2.5}
39+
\versionchanged[The \var{bind_and_activate} parameter was added]{2.6}
3340
\end{classdesc}
3441

3542
\begin{classdesc}{CGIXMLRPCRequestHandler}{\optional{allow_none\optional{, encoding}}}

Lib/DocXMLRPCServer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ class DocXMLRPCServer( SimpleXMLRPCServer,
252252
"""
253253

254254
def __init__(self, addr, requestHandler=DocXMLRPCRequestHandler,
255-
logRequests=1):
256-
SimpleXMLRPCServer.__init__(self, addr, requestHandler, logRequests)
255+
logRequests=1, allow_none=False, encoding=None,
256+
bind_and_activate=True):
257+
SimpleXMLRPCServer.__init__(self, addr, requestHandler, logRequests,
258+
allow_none, encoding, bind_and_activate)
257259
XMLRPCDocGenerator.__init__(self)
258260

259261
class DocCGIXMLRPCRequestHandler( CGIXMLRPCRequestHandler,

Lib/SimpleXMLRPCServer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,11 @@ class SimpleXMLRPCServer(SocketServer.TCPServer,
518518
allow_reuse_address = True
519519

520520
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
521-
logRequests=True, allow_none=False, encoding=None):
521+
logRequests=True, allow_none=False, encoding=None, bind_and_activate=True):
522522
self.logRequests = logRequests
523523

524524
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
525-
SocketServer.TCPServer.__init__(self, addr, requestHandler)
525+
SocketServer.TCPServer.__init__(self, addr, requestHandler, bind_and_activate)
526526

527527
# [Bug #1222790] If possible, set close-on-exec flag; if a
528528
# method spawns a subprocess, the subprocess shouldn't have

Lib/SocketServer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class TCPServer(BaseServer):
279279
280280
Methods for the caller:
281281
282-
- __init__(server_address, RequestHandlerClass)
282+
- __init__(server_address, RequestHandlerClass, bind_and_activate=True)
283283
- serve_forever()
284284
- handle_request() # if you don't use serve_forever()
285285
- fileno() -> int # for select()
@@ -322,13 +322,14 @@ class TCPServer(BaseServer):
322322

323323
allow_reuse_address = False
324324

325-
def __init__(self, server_address, RequestHandlerClass):
325+
def __init__(self, server_address, RequestHandlerClass, bind_and_activate=True):
326326
"""Constructor. May be extended, do not override."""
327327
BaseServer.__init__(self, server_address, RequestHandlerClass)
328328
self.socket = socket.socket(self.address_family,
329329
self.socket_type)
330-
self.server_bind()
331-
self.server_activate()
330+
if bind_and_activate:
331+
self.server_bind()
332+
self.server_activate()
332333

333334
def server_bind(self):
334335
"""Called by constructor to bind the socket.

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ Core and builtins
156156
Library
157157
-------
158158

159+
- Patch #1599845: Add an option to disable the implicit calls to server_bind()
160+
and server_activate() in the constructors for TCPServer, SimpleXMLRPCServer
161+
and DocXMLRPCServer.
162+
159163
- Bug #1531963: Make SocketServer.TCPServer's server_address always
160164
be equal to calling getsockname() on the server's socket. Fixed by
161165
patch #1545011.

0 commit comments

Comments
 (0)