Attachment 'fix-plugin-errors.patch'

Download

   1 * looking for nirs@freeshell.org--2005/moin--fix--1.3--patch-59 to compare with
   2 * comparing to nirs@freeshell.org--2005/moin--fix--1.3--patch-59
   3 M  MoinMoin/wikirpc.py
   4 M  MoinMoin/Page.py
   5 M  MoinMoin/parser/wiki.py
   6 M  MoinMoin/request.py
   7 M  MoinMoin/wikiaction.py
   8 M  MoinMoin/wikimacro.py
   9 M  MoinMoin/wikiutil.py
  10 M  MoinMoin/formatter/text_python.py
  11 
  12 * modified files
  13 
  14 --- orig/MoinMoin/Page.py
  15 +++ mod/MoinMoin/Page.py
  16 @@ -1157,7 +1157,7 @@
  17          try:
  18              Parser = wikiutil.importPlugin(self.request.cfg, "parser", 
  19                                             self.pi_format, "Parser")
  20 -        except ImportError:
  21 +        except wikiutil.PluginMissingError:
  22              from MoinMoin.parser.plain import Parser
  23  
  24          # start wiki content div
  25 @@ -1242,7 +1242,7 @@
  26                  try:
  27                      parser = wikiutil.importPlugin(self.request.cfg, "parser",
  28                                                     self.pi_format, "Parser")
  29 -                except ImportError:
  30 +                except wikiutil.PluginMissingError:
  31                      pass
  32              return getattr(parser, 'caching', False)
  33          return False
  34 
  35 
  36 --- orig/MoinMoin/formatter/text_python.py
  37 +++ mod/MoinMoin/formatter/text_python.py
  38 @@ -185,7 +185,7 @@
  39              Dependencies = wikiutil.importPlugin(self.request.cfg, type,
  40                                                   processor_name,
  41                                                   "Dependencies")
  42 -        except AttributeError:
  43 +        except wikiutil.PluginAttributeError:
  44              Dependencies = self.defaultDependencies
  45          if self.__is_static(Dependencies):
  46              return self.formatter.processor(processor_name, lines, is_parser)
  47 
  48 
  49 --- orig/MoinMoin/parser/wiki.py
  50 +++ mod/MoinMoin/parser/wiki.py
  51 @@ -1129,10 +1129,10 @@
  52              self.processor = wikiutil.importPlugin(cfg, "processor", name,
  53                                                     "process")
  54              self.processor_is_parser = 0
  55 -        except ImportError:
  56 +        except wikiutil.PluginMissingError:
  57              try:
  58                  self.processor = wikiutil.importPlugin(cfg, "parser", name,
  59                                                     "Parser")
  60                  self.processor_is_parser = 1
  61 -            except ImportError:
  62 +            except wikiutil.PluginMissingError:
  63                  self.processor = None
  64 
  65 
  66 --- orig/MoinMoin/request.py
  67 +++ mod/MoinMoin/request.py
  68 @@ -493,12 +493,12 @@
  69          try:
  70              Theme = wikiutil.importPlugin(self.cfg, 'theme', 
  71                                            theme_name, 'Theme')
  72 -        except ImportError:
  73 +        except wikiutil.PluginMissingError:
  74              fallback = 1
  75              try:
  76                  Theme = wikiutil.importPlugin(self.cfg, 'theme',
  77                                                self.cfg.theme_default, 'Theme')
  78 -            except ImportError:
  79 +            except wikiutil.PluginMissingError:
  80                  fallback = 2
  81                  from MoinMoin.theme.modern import Theme
  82          self.theme = Theme(self)
  83 
  84 
  85 --- orig/MoinMoin/wikiaction.py
  86 +++ mod/MoinMoin/wikiaction.py
  87 @@ -778,7 +778,7 @@
  88      try:
  89          Formatter = wikiutil.importPlugin(request.cfg, "formatter", 
  90                                            formatterName, "Formatter")
  91 -    except ImportError:
  92 +    except wikiutil.PluginMissingError:
  93          # default to plain text formatter
  94          mimetype = "text/plain"
  95          from MoinMoin.formatter.text_plain import Formatter
  96 @@ -895,7 +895,7 @@
  97      try:
  98          handler = wikiutil.importPlugin(request.cfg, "action", action,
  99                                          identifier)
 100 -    except ImportError:
 101 +    except wikiutil.PluginMissingError:
 102          handler = globals().get('do_' + action)
 103          
 104      return handler
 105 
 106 
 107 --- orig/MoinMoin/wikimacro.py
 108 +++ mod/MoinMoin/wikimacro.py
 109 @@ -108,7 +108,7 @@
 110          self.name = macro_name
 111          try:
 112              execute = wikiutil.importPlugin(self.cfg, 'macro', macro_name)
 113 -        except ImportError:
 114 +        except wikiutil.PluginMissingError:
 115              try:
 116                  builtins = self.__class__
 117                  execute = getattr(builtins, '_macro_' + macro_name)
 118 @@ -116,7 +116,7 @@
 119                  if macro_name in i18n.languages:
 120                      execute = builtins._m_lang
 121                  else:
 122 -                    raise ImportError("Cannot load macro %s" % macro_name)        
 123 +                    raise ImportError("Cannot load macro %s" % macro_name)
 124          return execute(self, args)
 125  
 126      def _m_lang(self, text):
 127 @@ -140,7 +140,7 @@
 128          try:
 129              return wikiutil.importPlugin(self.request.cfg, 'macro',
 130                                           macro_name, 'Dependencies')
 131 -        except (ImportError, AttributeError):
 132 +        except wikiutil.PluginError:
 133              return self.defaultDependency
 134  
 135      def _macro_TitleSearch(self, args):
 136 
 137 
 138 --- orig/MoinMoin/wikirpc.py
 139 +++ mod/MoinMoin/wikirpc.py
 140 @@ -411,7 +411,7 @@
 141                  try:
 142                      fn = wikiutil.importPlugin(self.request.cfg, 'xmlrpc',
 143                                                 method, 'execute')
 144 -                except ImportError:
 145 +                except wikiutil.PluginMissingError:
 146                      response = xmlrpclib.Fault(1, "No such method: %s." %
 147                                                 method)
 148                  else:
 149 
 150 
 151 --- orig/MoinMoin/wikiutil.py
 152 +++ mod/MoinMoin/wikiutil.py
 153 @@ -538,74 +538,76 @@
 154  ### Plugins
 155  #############################################################################
 156  
 157 +class PluginError(Exception):
 158 +    """ Base class for plugin errors """
 159 +
 160 +class PluginMissingError(PluginError):
 161 +    """ Raised when a plugin is not found """
 162 +
 163 +class PluginAttributeError(PluginError):
 164 +    """ Raised when plugin does not contain an attribtue """
 165 +
 166 +
 167  def importPlugin(cfg, kind, name, function="execute"):
 168      """ Import wiki or builtin plugin
 169      
 170 -    Returns function from a plugin module. If the module can not be
 171 -    imported, raise ImportError. If function is not there, raise
 172 -    AttributeError.
 173 +    Returns function from a plugin module name. If name can not be
 174 +    imported, raise PluginMissingError. If function is missing, raise
 175 +    PluginAttributeError.
 176  
 177      kind may be one of 'action', 'formatter', 'macro', 'processor',
 178      'parser' or any other directory that exist in MoinMoin or
 179      data/plugin
 180  
 181      Wiki plugins will always override builtin plugins. If you want
 182 -    specific plugin, use either importWikiPlugin or importName directly.
 183 +    specific plugin, use either importWikiPlugin or importBuiltinPlugin
 184 +    directly.
 185      
 186      @param cfg: wiki config instance
 187      @param kind: what kind of module we want to import
 188      @param name: the name of the module
 189      @param function: the function name
 190 -    @rtype: callable
 191 +    @rtype: any object
 192      @return: "function" of module "name" of kind "kind", or None
 193      """
 194      try:
 195 -        plugin = importWikiPlugin(cfg, kind, name, function)
 196 -    except ImportError:
 197 -        modulename = 'MoinMoin.%s.%s' % (kind, name)
 198 -        plugin = pysupport.importName(modulename, function)
 199 -    return plugin
 200 +        return importWikiPlugin(cfg, kind, name, function)
 201 +    except PluginMissingError:
 202 +        return importBuiltinPlugin(kind, name, function)
 203 +
 204  
 205  def importWikiPlugin(cfg, kind, name, function):
 206 -    """ Import and cache plugin from the wiki data directory
 207 +    """ Import plugin from the wiki data directory
 208      
 209 -    Returns function from a plugin module. If the module can not be
 210 -    imported, raise ImportError. If function is not there, raise
 211 -    AttributeError.
 212 -
 213 -    We try to import only ONCE - then cache the plugin, even if we got
 214 -    None. This way we prevent expensive import of existing plugins for
 215 -    each call to a plugin.
 216 +    See importPlugin docstring.
 217 +    """
 218 +    if not name in wikiPlugins(kind, cfg):
 219 +        raise PluginMissingError
 220 +    moduleName = '%s.plugin.%s.%s' % (cfg.siteid, kind, name)
 221 +    return importNameFromPlugin(moduleName, function)
 222  
 223 -    @param cfg: wiki config instance
 224 -    @param kind: what kind of module we want to import
 225 -    @param name: the name of the module
 226 -    @param function: the function name
 227 -    @rtype: callable
 228 -    @return: "function" of module "name" of kind "kind"
 229 +
 230 +def importBuiltinPlugin(kind, name, function):
 231 +    """ Import builtin plugin from MoinMoin package 
 232 +    
 233 +    See importPlugin docstring.
 234 +    """
 235 +    if not name in builtinPlugins(kind):
 236 +        raise PluginMissingError
 237 +    moduleName = 'MoinMoin.%s.%s' % (kind, name)
 238 +    return importNameFromPlugin(moduleName, function)
 239 +
 240 +
 241 +def importNameFromPlugin(moduleName, name):
 242 +    """ Return name from plugin module 
 243 +    
 244 +    Raise PluginAttributeError if name does not exists.
 245      """
 246 +    module = __import__(moduleName, globals(), {}, [name])
 247      try:
 248 -        wikiPlugins = cfg._wiki_plugins
 249 +        return getattr(module, name)
 250      except AttributeError:
 251 -        wikiPlugins = cfg._wiki_plugins = {}
 252 -        
 253 -    # Wiki plugins are located under 'wikiconfigname.plugin' module.
 254 -    modulename = '%s.plugin.%s.%s' % (cfg.siteid, kind, name)
 255 -    # Try cache or import once from disk
 256 -    try:
 257 -        module = wikiPlugins[modulename]
 258 -    except KeyError:
 259 -        try:
 260 -            module = __import__(modulename, globals(), {}, ['dummy'])
 261 -        except ImportError:
 262 -            module = wikiPlugins[modulename] = None
 263 -    if module is None:
 264 -        raise ImportError
 265 -    return getattr(module, function)
 266 -
 267 -# If we use threads, make this function thread safe
 268 -if config.use_threads:
 269 -    importWikiPlugin = pysupport.makeThreadSafe(importWikiPlugin)
 270 +        raise PluginAttributeError
 271  
 272  
 273  def builtinPlugins(kind):
 274 @@ -675,7 +677,7 @@
 275          for pname in getPlugins('parser', cfg):
 276              try:
 277                  Parser = importPlugin(cfg, 'parser', pname, 'Parser')
 278 -            except ImportError:
 279 +            except wikiutil.PluginMissingError:
 280                  continue
 281              if hasattr(Parser, 'extensions'):
 282                  exts = Parser.extensions

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-10-17 16:58:08, 2.8 KB) [[attachment:dependency.patch]]
  • [get | view] (2005-09-09 21:43:34, 9.9 KB) [[attachment:fix-plugin-errors.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.