httpserver: Fix restarting the server once a plugin has been unloaded and loaded back.

This commit is contained in:
Valentin Lorentz 2013-05-31 17:55:35 +02:00
parent 2016983d35
commit b2d5544ccf
1 changed files with 10 additions and 8 deletions

View File

@ -281,7 +281,10 @@ class Supy404(SupyHTTPServerCallback):
self.send_header('Content_type', 'text/plain; charset=utf-8') self.send_header('Content_type', 'text/plain; charset=utf-8')
self.send_header('Content-Length', len(self.response)) self.send_header('Content-Length', len(self.response))
self.end_headers() self.end_headers()
self.wfile.write(self.response.encode()) response = self.response
if sys.version_info[0] >= 3:
response = response.encode()
self.wfile.write(response)
doPost = doHead = doGet doPost = doHead = doGet
@ -352,7 +355,7 @@ class Favicon(SupyHTTPServerCallback):
response = response.encode() response = response.encode()
self.wfile.write(response) self.wfile.write(response)
http_servers = None http_servers = []
def startServer(): def startServer():
"""Starts the HTTP server. Shouldn't be called from other modules. """Starts the HTTP server. Shouldn't be called from other modules.
@ -373,18 +376,17 @@ def stopServer():
"""Stops the HTTP server. Should be run only from this module or from """Stops the HTTP server. Should be run only from this module or from
when the bot is dying (ie. from supybot.world)""" when the bot is dying (ie. from supybot.world)"""
global http_servers global http_servers
if http_servers is not None: for server in http_servers:
for server in http_servers: log.info('Stopping HTTP server: %s' % str(server))
log.info('Stopping HTTP server: %s' % str(server)) server.shutdown()
server.shutdown() server = None
server = None
if configGroup.keepAlive(): if configGroup.keepAlive():
startServer() startServer()
def hook(subdir, callback): def hook(subdir, callback):
"""Sets a callback for a given subdir.""" """Sets a callback for a given subdir."""
if http_servers is None: if not http_servers:
startServer() startServer()
assert isinstance(http_servers, list) assert isinstance(http_servers, list)
for server in http_servers: for server in http_servers: