mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 14:40:51 +01:00
Bug fixes to the HTTP server
This commit is contained in:
parent
ef5438e937
commit
667d7c34b4
@ -330,12 +330,12 @@ if __name__ == '__main__':
|
|||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
import supybot.plugins.Owner as Owner
|
import supybot.plugins.Owner as Owner
|
||||||
|
|
||||||
owner = Owner.Class()
|
|
||||||
|
|
||||||
# These may take some resources, and it does not need to be run while boot, so
|
# These may take some resources, and it does not need to be run while boot, so
|
||||||
# we import it as late as possible.
|
# we import it as late as possible (but before plugins are loaded).
|
||||||
import supybot.utils.httpserver as httpserver
|
import supybot.utils.httpserver as httpserver
|
||||||
|
|
||||||
|
owner = Owner.Class()
|
||||||
|
|
||||||
if options.profile:
|
if options.profile:
|
||||||
import profile
|
import profile
|
||||||
world.profiling = True
|
world.profiling = True
|
||||||
|
@ -70,12 +70,12 @@ class SupyHTTPServer(HTTPServer):
|
|||||||
callbacks = {}
|
callbacks = {}
|
||||||
running = False
|
running = False
|
||||||
def hook(self, subdir, callback):
|
def hook(self, subdir, callback):
|
||||||
if subdir in callbacks:
|
if subdir in self.callbacks:
|
||||||
raise KeyError('This subdir is already hooked.')
|
raise KeyError('This subdir is already hooked.')
|
||||||
else:
|
else:
|
||||||
callbacks[subdir] = callback
|
self.callbacks[subdir] = callback
|
||||||
def unhook(self, subdir):
|
def unhook(self, subdir):
|
||||||
callback = callbacks.pop(subdir) # May raise a KeyError. We don't care.
|
callback = self.callbacks.pop(subdir) # May raise a KeyError. We don't care.
|
||||||
callback.doUnhook(self)
|
callback.doUnhook(self)
|
||||||
return callback
|
return callback
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class SupyHTTPRequestHandler(BaseHTTPRequestHandler):
|
|||||||
else:
|
else:
|
||||||
subdir = self.path.split('/')[1]
|
subdir = self.path.split('/')[1]
|
||||||
try:
|
try:
|
||||||
callback = self.server.callbacks[subdir]()
|
callback = self.server.callbacks[subdir]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
callback = Supy404()
|
callback = Supy404()
|
||||||
|
|
||||||
@ -147,17 +147,18 @@ class SupyIndex(SupyHTTPServerCallback):
|
|||||||
<title>Supybot Web server index</title>
|
<title>Supybot Web server index</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
Here is a list of the plugins that have a Web interface:
|
<p>Here is a list of the plugins that have a Web interface:</p>
|
||||||
%s
|
%s
|
||||||
</body>
|
</body>
|
||||||
</html>"""
|
</html>"""
|
||||||
def doGet(self, handler, path):
|
def doGet(self, handler, path):
|
||||||
plugins = [x for x in handler.server.callbacks.items()]
|
plugins = [x for x in handler.server.callbacks.items()]
|
||||||
if plugins == []:
|
if plugins == []:
|
||||||
response = 'No plugins available.'
|
plugins = 'No plugins available.'
|
||||||
else:
|
else:
|
||||||
response = '<ul><li>%s</li></ul>' % '</li><li>'.join(
|
plugins = '<ul><li>%s</li></ul>' % '</li><li>'.join(
|
||||||
['<a href="/%s">%s</a>' % x in plugins])
|
['<a href="/%s">%s</a>' % (x,y.name) for x,y in plugins])
|
||||||
|
response = self.template % plugins
|
||||||
handler.send_response(200)
|
handler.send_response(200)
|
||||||
self.send_header('Content_type', 'text/html')
|
self.send_header('Content_type', 'text/html')
|
||||||
self.send_header('Content-Length', len(response))
|
self.send_header('Content-Length', len(response))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user