1.1 --- a/MoinSupport.py Mon Feb 18 18:50:02 2013 +0100
1.2 +++ b/MoinSupport.py Sun Mar 10 01:16:50 2013 +0100
1.3 @@ -4,7 +4,10 @@
1.4
1.5 @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
1.6 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
1.7 - 2005-2008 MoinMoin:ThomasWaldmann.
1.8 + 2004 by Florian Festi,
1.9 + 2006 by Mikko Virkkil,
1.10 + 2005-2008 MoinMoin:ThomasWaldmann,
1.11 + 2007 MoinMoin:ReimarBauer.
1.12 @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.13 """
1.14
1.15 @@ -26,7 +29,7 @@
1.16 except ImportError:
1.17 pass
1.18
1.19 -__version__ = "0.2.1"
1.20 +__version__ = "0.3"
1.21
1.22 # Extraction of shared fragments.
1.23
1.24 @@ -425,6 +428,33 @@
1.25 else:
1.26 return token
1.27
1.28 +# Macro argument parsing.
1.29 +
1.30 +def parseMacroArguments(args):
1.31 +
1.32 + """
1.33 + Interpret the arguments. To support commas in labels, the label argument
1.34 + should be quoted. For example:
1.35 +
1.36 + "label=No, thanks!"
1.37 + """
1.38 +
1.39 + try:
1.40 + parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or []
1.41 + except AttributeError:
1.42 + parsed_args = args.split(",")
1.43 +
1.44 + pairs = []
1.45 + for arg in parsed_args:
1.46 + if arg:
1.47 + pair = arg.split("=", 1)
1.48 + if len(pair) < 2:
1.49 + pairs.append((None, arg))
1.50 + else:
1.51 + pairs.append(tuple(pair))
1.52 +
1.53 + return pairs
1.54 +
1.55 # Request-related classes and associated functions.
1.56
1.57 class Form:
1.58 @@ -758,6 +788,48 @@
1.59 buf.close()
1.60 return text
1.61
1.62 +# Finding components for content types.
1.63 +
1.64 +def getParsersForContentType(cfg, mimetype):
1.65 +
1.66 + """
1.67 + Find parsers that support the given 'mimetype', constructing a dictionary
1.68 + mapping content types to lists of parsers that is then cached in the 'cfg'
1.69 + object. A list of suitable parsers is returned for 'mimetype'.
1.70 + """
1.71 +
1.72 + if not hasattr(cfg.cache, "MIMETYPE_TO_PARSER"):
1.73 + available = {}
1.74 +
1.75 + for name in wikiutil.getPlugins("parser", cfg):
1.76 +
1.77 + # Import each parser in order to inspect supported content types.
1.78 +
1.79 + try:
1.80 + parser_cls = wikiutil.importPlugin(cfg, "parser", name, "Parser")
1.81 + except wikiutil.PluginMissingError:
1.82 + continue
1.83 +
1.84 + # Attempt to determine supported content types.
1.85 + # NOTE: Extensions and /etc/mime.types (or equivalent) could also be
1.86 + # NOTE: used.
1.87 +
1.88 + if hasattr(parser_cls, "input_mimetypes"):
1.89 + for input_mimetype in parser_cls.input_mimetypes:
1.90 + if not available.has_key(input_mimetype):
1.91 + available[input_mimetype] = []
1.92 + available[input_mimetype].append(parser_cls)
1.93 +
1.94 + # Support some basic parsers.
1.95 +
1.96 + elif name == "text_moin_wiki":
1.97 + available["text/moin-wiki"] = [parser_cls]
1.98 + available["text/moin"] = [parser_cls]
1.99 +
1.100 + cfg.cache.MIMETYPE_TO_PARSER = available
1.101 +
1.102 + return cfg.cache.MIMETYPE_TO_PARSER.get(mimetype, [])
1.103 +
1.104 # Textual representations.
1.105
1.106 def getSimpleWikiText(text):