Attachment 'dependency.patch'
Download 1 * looking for nirs@freeshell.org--2005/moin--fix--1.3--patch-65 to compare with
2 * comparing to nirs@freeshell.org--2005/moin--fix--1.3--patch-65
3 M MoinMoin/parser/rst.py
4 M MoinMoin/wikiutil.py
5
6 * modified files
7
8 --- orig/MoinMoin/parser/rst.py
9 +++ mod/MoinMoin/parser/rst.py
10 @@ -40,7 +40,12 @@
11 urlopen = staticmethod(urlopen)
12
13 # # # All docutils imports must be contained below here
14 -import docutils
15 +try:
16 + import docutils
17 +except ImportError, err:
18 + from MoinMoin import wikiutil
19 + raise wikiutil.PluginDependencyError(str(err))
20 +
21 from docutils.core import publish_parts
22 from docutils.writers import html4css1
23 from docutils.nodes import fully_normalize_name, reference
24
25
26 --- orig/MoinMoin/wikiutil.py
27 +++ mod/MoinMoin/wikiutil.py
28 @@ -544,6 +544,9 @@
29 class PluginMissingError(PluginError):
30 """ Raised when a plugin is not found """
31
32 +class PluginDependencyError(PluginMissingError):
33 + """ Raised when plugin can't get a dependency """
34 +
35 class PluginAttributeError(PluginError):
36 """ Raised when plugin does not contain an attribtue """
37
38 @@ -583,8 +586,8 @@
39 """
40 if not name in wikiPlugins(kind, cfg):
41 raise PluginMissingError
42 - moduleName = '%s.plugin.%s.%s' % (cfg.siteid, kind, name)
43 - return importNameFromPlugin(moduleName, function)
44 + package = '%s.plugin.%s' % (cfg.siteid, kind)
45 + return importNameFromPlugin(package, name, function)
46
47
48 def importBuiltinPlugin(kind, name, function):
49 @@ -594,21 +597,38 @@
50 """
51 if not name in builtinPlugins(kind):
52 raise PluginMissingError
53 - moduleName = 'MoinMoin.%s.%s' % (kind, name)
54 - return importNameFromPlugin(moduleName, function)
55 + package = 'MoinMoin.%s' % kind
56 + return importNameFromPlugin(package, name, function)
57
58
59 -def importNameFromPlugin(moduleName, name):
60 +def importNameFromPlugin(package, plugin, name):
61 """ Return name from plugin module
62
63 - Raise PluginAttributeError if name does not exists.
64 + Raise PluginDependencyError if the plugin raise it. Raise
65 + PluginAttributeError if name does not exists.
66 """
67 - module = __import__(moduleName, globals(), {}, [name])
68 + try:
69 + qualifiedName = '%s.%s' % (package, plugin)
70 + module = __import__(qualifiedName, globals, {}, [name])
71 + except PluginDependencyError:
72 + unregisterPlugin(package, plugin)
73 + raise
74 + try:
75 + return getattr(module, name)
76 + except AttributeError:
77 + raise PluginAttributeError
78 +
79 try:
80 return getattr(module, name)
81 except AttributeError:
82 raise PluginAttributeError
83
84 +
85 +def unregisterPlugin(package, plugin):
86 + """ Remove a plugin from the plugin registry """
87 + package = __import__(package, globals, {}, ['modules'])
88 + package.modules.remove(plugin)
89 +
90
91 def builtinPlugins(kind):
92 """ Gets a list of modules in MoinMoin.'kind'
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.You are not allowed to attach a file to this page.