From 667d7c34b44a3989302084b019ca9ecb4acff962 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 24 Jun 2011 15:32:22 +0200 Subject: [PATCH] Bug fixes to the HTTP server --- scripts/supybot | 6 +++--- src/utils/httpserver.py | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/supybot b/scripts/supybot index c60a5f849..6c7688ecd 100644 --- a/scripts/supybot +++ b/scripts/supybot @@ -330,12 +330,12 @@ if __name__ == '__main__': import supybot.callbacks as callbacks 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 - # 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 + owner = Owner.Class() + if options.profile: import profile world.profiling = True diff --git a/src/utils/httpserver.py b/src/utils/httpserver.py index 4fad4b12a..23ccb7cc6 100644 --- a/src/utils/httpserver.py +++ b/src/utils/httpserver.py @@ -70,12 +70,12 @@ class SupyHTTPServer(HTTPServer): callbacks = {} running = False def hook(self, subdir, callback): - if subdir in callbacks: + if subdir in self.callbacks: raise KeyError('This subdir is already hooked.') else: - callbacks[subdir] = callback + self.callbacks[subdir] = callback 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) return callback @@ -86,7 +86,7 @@ class SupyHTTPRequestHandler(BaseHTTPRequestHandler): else: subdir = self.path.split('/')[1] try: - callback = self.server.callbacks[subdir]() + callback = self.server.callbacks[subdir] except KeyError: callback = Supy404() @@ -147,17 +147,18 @@ class SupyIndex(SupyHTTPServerCallback): Supybot Web server index - Here is a list of the plugins that have a Web interface: +

Here is a list of the plugins that have a Web interface:

%s """ def doGet(self, handler, path): plugins = [x for x in handler.server.callbacks.items()] if plugins == []: - response = 'No plugins available.' + plugins = 'No plugins available.' else: - response = '' % '
  • '.join( - ['%s' % x in plugins]) + plugins = '' % '
  • '.join( + ['%s' % (x,y.name) for x,y in plugins]) + response = self.template % plugins handler.send_response(200) self.send_header('Content_type', 'text/html') self.send_header('Content-Length', len(response))