# HG changeset patch # User Paul Boddie # Date 1371163453 -7200 # Node ID 75848522fcf5dda34cad265f870fd935597b7e3f # Parent 129eb3495f2df54ed7b1ee9bab6f80a9f0c6cfb5 Added various parsing and formatting utility methods for enhanced parsers. Fixed/updated copyright information. diff -r 129eb3495f2d -r 75848522fcf5 MoinSupport.py --- a/MoinSupport.py Fri Jun 07 23:41:04 2013 +0200 +++ b/MoinSupport.py Fri Jun 14 00:44:13 2013 +0200 @@ -3,11 +3,12 @@ MoinMoin - MoinSupport library (derived from EventAggregatorSupport) @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie - @copyright: 2000-2004 Juergen Hermann , - 2004 by Florian Festi, - 2006 by Mikko Virkkil, - 2005-2008 MoinMoin:ThomasWaldmann, - 2007 MoinMoin:ReimarBauer. + @copyright: 2000-2004 Juergen Hermann + 2004 by Florian Festi + 2006 by Mikko Virkkil + 2005-2008 MoinMoin:ThomasWaldmann + 2007 MoinMoin:ReimarBauer + 2008 MoinMoin:FlorianKrupicka (redirectedOutput code) @license: GNU GPL (v2 or later), see COPYING.txt for details. """ @@ -767,6 +768,26 @@ # Page parsing and formatting of embedded content. +def getOutputTypes(request, format): + + """ + Using the 'request' and the 'format' of a fragment, return the media types + available for the fragment. + """ + + return getParserOutputTypes(getParserClass(request, format)) + +def getParserOutputTypes(parser): + + "Return the media types supported by the given 'parser'." + + # This uses an extended parser API method if available. + + if parser and hasattr(parser, "getOutputTypes"): + return parser.getOutputTypes() + else: + return ["text/html"] + def getPageParserClass(request): "Using 'request', return a parser class for the current page's format." @@ -820,6 +841,21 @@ finally: request.formatter = old_fmt +def formatTextForOutputType(text, request, parser_cls, output_type): + + """ + Format the given 'text' using the specified 'request' and parser class + 'parser_cls', producing output of the given 'output_type'. + """ + + parser = parser_cls(text, request) + buf = StringIO() + try: + parser.formatForOutputType(output_type, buf.write) + return buf.getvalue() + finally: + buf.close() + def redirectedOutput(request, parser, fmt, **kw): "A fixed version of the request method of the same name." diff -r 129eb3495f2d -r 75848522fcf5 README.txt --- a/README.txt Fri Jun 07 23:41:04 2013 +0200 +++ b/README.txt Fri Jun 14 00:44:13 2013 +0200 @@ -76,6 +76,7 @@ * Added a common wikidict entry parsing function. * Added a superuser parameter to getWikiDict to make the function usable by auth handlers. + * Added various parsing and formatting utility methods for enhanced parsers. New in MoinSupport 0.3 (Changes since MoinSupport 0.2) ------------------------------------------------------ diff -r 129eb3495f2d -r 75848522fcf5 docs/COPYING.txt --- a/docs/COPYING.txt Fri Jun 07 23:41:04 2013 +0200 +++ b/docs/COPYING.txt Fri Jun 14 00:44:13 2013 +0200 @@ -8,7 +8,11 @@ and are thus covered by the following copyrights: Copyright (C) 2000-2004 Juergen Hermann +Copyright (C) 2004 by Florian Festi Copyright (C) 2005-2008 MoinMoin:ThomasWaldmann +Copyright (C) 2006 by Mikko Virkkil +Copyright (C) 2007 MoinMoin:ReimarBauer +Copyright (C) 2008 MoinMoin:FlorianKrupicka (redirectedOutput code) This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as