# HG changeset patch # User Paul Boddie # Date 1396556714 -7200 # Node ID bca53f2afce89390d47534a8491c9867833656a5 # Parent 006442452766085502241f74d53a3eb244439998 Added a plain text parser, useful for e-mail messages. Fixed docstrings in the PGP keys parser. diff -r 006442452766 -r bca53f2afce8 parsers/pgp_keys.py --- a/parsers/pgp_keys.py Wed Apr 02 23:57:59 2014 +0200 +++ b/parsers/pgp_keys.py Thu Apr 03 22:25:14 2014 +0200 @@ -2,7 +2,7 @@ """ MoinMoin - pgp_keys (MoinShare) - @copyright: 2012, 2013 by Paul Boddie + @copyright: 2012, 2013, 2014 by Paul Boddie @license: GNU GPL (v2 or later), see COPYING.txt for details. """ @@ -43,7 +43,7 @@ def format(self, fmt, write=None): """ - Format a table using the given formatter 'fmt'. If the 'write' parameter + Format a key using the given formatter 'fmt'. If the 'write' parameter is specified, use it to write output; otherwise, write output using the request. """ @@ -55,7 +55,7 @@ def formatForOutputType(self, mimetype, write=None): """ - Format a table for the given 'mimetype'. If the 'write' parameter is + Format a key for the given 'mimetype'. If the 'write' parameter is specified, use it to write output; otherwise, write output using the request. """ diff -r 006442452766 -r bca53f2afce8 parsers/text_plain.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/parsers/text_plain.py Thu Apr 03 22:25:14 2014 +0200 @@ -0,0 +1,78 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - text_plain (MoinShare) + + @copyright: 2012, 2013, 2014 by Paul Boddie + @license: GNU GPL (v2 or later), see COPYING.txt for details. +""" + +from MoinSupport import parseAttributes + +Dependencies = ["pages"] + +# Parser support. + +class Parser: + + "Display data in text/plain format." + + Dependencies = Dependencies + extensions = [".txt"] + + # Input content types understood by this parser. + + input_mimetypes = ["text/plain"] + + # Output content types preferred by this parser. + + output_mimetypes = ["text/plain", "text/html"] + + def __init__(self, raw, request, **kw): + + """ + Initialise the parser with the given 'raw' data, 'request' and any + keyword arguments that may have been supplied. + """ + + self.raw = raw + self.request = request + self.attrs = parseAttributes(kw.get("format_args", ""), False) + + def format(self, fmt, write=None): + + """ + Format plain text using the given formatter 'fmt'. If the 'write' + parameter is specified, use it to write output; otherwise, write output + using the request. + """ + + (write or self.request.write)(fmt.text(self.raw)) + + # Extra API methods. + + def formatForOutputType(self, mimetype, write=None): + + """ + Format plain text for the given 'mimetype'. If the 'write' parameter is + specified, use it to write output; otherwise, write output using the + request. + """ + + request = self.request + write = write or request.write + fmt = request.html_formatter + _ = request.getText + + if mimetype == "text/html": + self.format(fmt, write) + elif mimetype == "text/plain": + write(self.raw) + + # Class methods. + + def getOutputTypes(self): + return self.output_mimetypes + + getOutputTypes = classmethod(getOutputTypes) + +# vim: tabstop=4 expandtab shiftwidth=4