changeset 2462:8ce2afa469a7

Merge main.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Fri, 20 Jul 2007 00:24:56 +0200
parents f456dc2048d1 (current diff) d268d5467cfe (diff)
children 920089399dfa
files MoinMoin/xmlrpc/__init__.py
diffstat 9 files changed, 86 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Fri Jul 20 00:24:21 2007 +0200
+++ b/MoinMoin/config/multiconfig.py	Fri Jul 20 00:24:56 2007 +0200
@@ -205,6 +205,9 @@
 class DefaultConfig:
     """ default config values """
 
+    # internal dict for plugin `modules' lists
+    _site_plugin_lists = {}
+
     # setting DesktopEdition = True gives all local users special powers - ONLY use for MMDE style usage!
     DesktopEdition = False
 
--- a/MoinMoin/failure.py	Fri Jul 20 00:24:21 2007 +0200
+++ b/MoinMoin/failure.py	Fri Jul 20 00:24:56 2007 +0200
@@ -9,6 +9,8 @@
 import sys, os, logging
 
 from MoinMoin.support import cgitb
+from MoinMoin.error import ConfigurationError
+from traceback import extract_tb
 
 
 class View(cgitb.View):
@@ -61,20 +63,31 @@
     def formatMessage(self):
         """ handle multiple paragraphs messages and add general help """
         f = self.formatter
-        text = [self.formatExceptionMessage(self.info),
+        text = [self.formatExceptionMessage(self.info)]
+
+        if self.info[0] == ConfigurationError:
+            tbt = extract_tb(self.info[1].exceptions()[-1][2])[-1]
+            text.append(
+                f.paragraph('Error in your configuration file "%s"'
+                            ' around line %d.' % tbt[:2]))
+        else:
+            text.append(
                 f.paragraph("If you want to report a bug, please save "
-                            "this page and  attach it to your bug report."), ]
+                            "this page and  attach it to your bug report."))
         return ''.join(text)
 
     def formatButtons(self):
         """ Add 'buttons' to the error dialog """
         f = self.formatter
         buttons = [f.link('javascript:toggleDebugInfo()',
-                          'Show debugging information'),
+                          'Show debugging information')]
+        if self.info[0] != ConfigurationError:
+            buttons.append(
                    f.link('http://moinmoin.wikiwikiweb.de/MoinMoinBugs',
-                          'Report bug'),
+                          'Report bug'))
+            buttons.append(
                    f.link('http://moinmoin.wikiwikiweb.de/FrontPage',
-                          'Visit MoinMoin wiki'), ]
+                          'Visit MoinMoin wiki'))
         return f.list(buttons, {'class': 'buttons'})
 
     def formatDebugInfo(self):
@@ -143,9 +156,14 @@
     logging.error('%s: %s' % (err.__class__.__name__, str(err)), exc_info=savedError)
     try:
         debug = 'debug' in getattr(request, 'form', {})
-        handler = cgitb.Hook(file=request,
-                             display=request.cfg.traceback_show,
-                             logdir=request.cfg.traceback_log_dir,
+        # default to True here to allow an admin setting up the wiki
+        # to see the errors made in the configuration file
+        display = True
+        logdir = None
+        if hasattr(request, 'cfg'):
+            display = request.cfg.traceback_show
+            logdir = request.cfg.traceback_log_dir
+        handler = cgitb.Hook(file=request, display=display, logdir=logdir,
                              viewClass=View, debug=debug)
         handler.handle()
     except:
--- a/MoinMoin/server/server_standalone.py	Fri Jul 20 00:24:21 2007 +0200
+++ b/MoinMoin/server/server_standalone.py	Fri Jul 20 00:24:56 2007 +0200
@@ -77,6 +77,9 @@
         if config.hotshotProfile:
             config.hotshotProfile.close()
 
+        if config.cProfileProfile and config.cProfile:
+            config.cProfile.dump_stats(config.cProfileProfile)
+
         # Set abort flag, then make request to wake the server
         self._abort = 1
         try:
@@ -559,8 +562,22 @@
     # Development options
     memoryProfile = None
     hotshotProfile = None
+    cProfile = None # internal use only
+    cProfileProfile = None
     pycallgraph_output = None
 
+def cProfileDecorator(func, profile):
+    """ Return a profiled function """
+    profile.moin_requests_done = 0
+    def profiledFunction(*args, **kw):
+        profile.moin_requests_done += 1
+        if profile.moin_requests_done == 1:
+            # Don't profile first request, it's not interesting
+            return func(*args, **kw)
+        return profile.runcall(func, *args, **kw)
+
+    return profiledFunction
+
 def run(configClass):
     """ Create and run a moin server
 
@@ -575,6 +592,9 @@
 
     config = configClass()
 
+    if config.hotshotProfile and config.cProfileProfile:
+        raise RuntimeError("You cannot run two profilers simultaneously.")
+
     # Install hotshot profiled serve_moin method. To compare with other
     # servers, we profile the part that create and run the request.
     if config.hotshotProfile:
@@ -583,6 +603,14 @@
         MoinRequestHandler.serve_moin = hotshotProfileDecorator(
             MoinRequestHandler.serve_moin, config.hotshotProfile)
 
+    if config.cProfileProfile:
+        import cProfile
+        # Create a new cProfile.Profile object using config.cProfileProfile
+        # as the path for the output file.
+        config.cProfile = cProfile.Profile()
+        MoinRequestHandler.serve_moin = cProfileDecorator(
+            MoinRequestHandler.serve_moin, config.cProfile)
+
     # Install a memory profiled serve_moin method
     if config.memoryProfile:
         config.memoryProfile.sample()
--- a/MoinMoin/userprefs/oid.py	Fri Jul 20 00:24:21 2007 +0200
+++ b/MoinMoin/userprefs/oid.py	Fri Jul 20 00:24:56 2007 +0200
@@ -29,14 +29,14 @@
         self._ = request.getText
         self.cfg = request.cfg
         self.title = self._("OpenID settings")
-
-    def allowed(self):
-        if _openid_disabled:
-            return False
-        for authm in self.request.cfg.auth:
-            if isinstance(authm, OpenIDAuth):
-                return UserPrefBase.allowed(self)
-        return False
+        openid_auth = False
+        if not _openid_disabled:
+            for authm in self.request.cfg.auth:
+                if isinstance(authm, OpenIDAuth):
+                    openid_auth = True
+                    break
+        if not openid_auth:
+            self.allowed = lambda: False
 
     def _handle_remove(self):
         _ = self.request.getText
--- a/MoinMoin/wikiutil.py	Fri Jul 20 00:24:21 2007 +0200
+++ b/MoinMoin/wikiutil.py	Fri Jul 20 00:24:56 2007 +0200
@@ -1090,16 +1090,25 @@
 def wikiPlugins(kind, cfg):
     """ Gets a list of modules in data/plugin/'kind'
 
-    Require valid plugin directory. e.g missing 'parser' directory or
-    missing '__init__.py' file will raise errors.
-
     @param kind: what kind of modules we look for
     @rtype: list
     @return: module names
     """
     # Wiki plugins are located in wikiconfig.plugin module
     modulename = '%s.plugin.%s' % (cfg.siteid, kind)
-    return pysupport.importName(modulename, "modules")
+
+    # short-cut if we've loaded the list already
+    # (or already failed to load it)
+    if kind in cfg._site_plugin_lists:
+        return cfg._site_plugin_lists[kind]
+
+    try:
+        plugins = pysupport.importName(modulename, "modules")
+        cfg._site_plugin_lists[kind] = plugins
+        return plugins
+    except ImportError:
+        cfg._site_plugin_lists[kind] = []
+        return []
 
 
 def getPlugins(kind, cfg):
--- a/MoinMoin/xmlrpc/__init__.py	Fri Jul 20 00:24:21 2007 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Fri Jul 20 00:24:56 2007 +0200
@@ -609,7 +609,7 @@
 
     # authorization methods
 
-    def _cleanup_stale_tokens(request):
+    def _cleanup_stale_tokens(self, request):
         items = caching.get_cache_list(request, 'xmlrpc-session', 'farm')
         tnow = time.time()
         for item in items:
--- a/moin.py	Fri Jul 20 00:24:21 2007 +0200
+++ b/moin.py	Fri Jul 20 00:24:56 2007 +0200
@@ -127,6 +127,10 @@
     # Not compatible with threads - use with SimpleServer only.
     ## hotshotProfile = name + '.prof'
 
+    # cProfile profile (default commented)
+    # Use with SimpleServer only.
+    ## cProfileProfile = name + '.prof'
+
     # Using pycallgraph to make nice graphics of how moin works internally
     # hint: using zgrviewer to view .dot is much more effective than using
     #       some .png viewer
--- a/wiki/server/moin.cgi	Fri Jul 20 00:24:21 2007 +0200
+++ b/wiki/server/moin.cgi	Fri Jul 20 00:24:56 2007 +0200
@@ -26,7 +26,7 @@
 ## import os
 ## os.environ['MOIN_DEBUG'] = '1'
 
-from MoinMoin.server.CGI import CgiConfig, run
+from MoinMoin.server.server_cgi import CgiConfig, run
 
 class Config(CgiConfig):
     # Server name
--- a/wiki/server/moin.fcg	Fri Jul 20 00:24:21 2007 +0200
+++ b/wiki/server/moin.fcg	Fri Jul 20 00:24:56 2007 +0200
@@ -50,11 +50,11 @@
 config.use_threads = max_threads > 1
 del config
 
-from MoinMoin.request import FCGI
+from MoinMoin.request import request_fcgi
 from MoinMoin.support import thfcgi
 
 def handle_request(req, env, form):
-    request = FCGI.Request(req, env, form)
+    request = request_fcgi.Request(req, env, form)
     request.run()
 
 if __name__ == '__main__':