# HG changeset patch # User Paul Boddie # Date 1338835958 -7200 # Node ID 6ccdbf15d1a19f86bab704a4afbd83205a7aeabd # Parent 72dcf13893765134448eea5a49690940523b6970 Added common parsing/formatting-related code from EventAggregator and ImprovedTableParser. diff -r 72dcf1389376 -r 6ccdbf15d1a1 MoinSupport.py --- a/MoinSupport.py Wed Apr 18 01:17:58 2012 +0200 +++ b/MoinSupport.py Mon Jun 04 20:52:38 2012 +0200 @@ -534,6 +534,36 @@ return {"timestamp" : DateTime(time.gmtime(mtime)[:6] + (None,)), "comment" : comment} +# Page parsing and formatting of embedded content. + +def getParserClass(request, format): + + """ + Return a parser class using the 'request' for the given 'format', returning + a plain text parser if no parser can be found for the specified 'format'. + """ + + try: + return wikiutil.searchAndImportPlugin(request.cfg, "parser", format or "plain") + except wikiutil.PluginMissingError: + return wikiutil.searchAndImportPlugin(request.cfg, "parser", "plain") + +def redirectedOutput(request, parser, fmt, **kw): + + "A fixed version of the request method of the same name." + + buf = StringIO() + request.redirect(buf) + try: + parser.format(fmt, **kw) + if hasattr(fmt, "flush"): + buf.write(fmt.flush(True)) + finally: + request.redirect() + text = buf.getvalue() + buf.close() + return text + # User interface functions. def getParameter(request, name, default=None):