paul@0 | 1 | # -*- coding: iso-8859-1 -*- |
paul@0 | 2 | """ |
paul@0 | 3 | MoinMoin - form (MoinForms) |
paul@0 | 4 | |
paul@0 | 5 | @copyright: 2012 by Paul Boddie <paul@boddie.org.uk> |
paul@0 | 6 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@0 | 7 | """ |
paul@0 | 8 | |
paul@0 | 9 | from MoinForms import * |
paul@0 | 10 | from MoinSupport import * |
paul@0 | 11 | |
paul@0 | 12 | Dependencies = ["pages"] |
paul@0 | 13 | |
paul@0 | 14 | # Parser support. |
paul@0 | 15 | |
paul@0 | 16 | class Parser: |
paul@0 | 17 | |
paul@0 | 18 | "Manipulate and display forms." |
paul@0 | 19 | |
paul@0 | 20 | Dependencies = Dependencies |
paul@0 | 21 | extensions = [] |
paul@0 | 22 | |
paul@0 | 23 | # Output content types preferred by this parser. |
paul@0 | 24 | |
paul@0 | 25 | output_mimetypes = ["text/html"] |
paul@0 | 26 | |
paul@0 | 27 | def __init__(self, raw, request, **kw): |
paul@0 | 28 | |
paul@0 | 29 | """ |
paul@0 | 30 | Initialise the parser with the given 'raw' data, 'request' and any |
paul@0 | 31 | keyword arguments that may have been supplied. |
paul@0 | 32 | """ |
paul@0 | 33 | |
paul@0 | 34 | self.raw = raw |
paul@0 | 35 | self.request = request |
paul@1 | 36 | self.attrs = parseAttributes(kw.get("format_args", ""), False) |
paul@0 | 37 | |
paul@0 | 38 | def format(self, fmt, write=None): |
paul@0 | 39 | |
paul@0 | 40 | """ |
paul@0 | 41 | Format an event using the given formatter 'fmt'. If the 'write' |
paul@0 | 42 | parameter is specified, use it to write output; otherwise, write output |
paul@0 | 43 | using the request. |
paul@0 | 44 | """ |
paul@0 | 45 | |
paul@1 | 46 | formatForm(self.raw, self.request, fmt, self.attrs, write=write) |
paul@0 | 47 | |
paul@0 | 48 | # Extra API methods. |
paul@0 | 49 | |
paul@0 | 50 | def formatForOutputType(self, mimetype, write=None): |
paul@0 | 51 | |
paul@0 | 52 | """ |
paul@0 | 53 | Format an event for the given 'mimetype'. If the 'write' parameter is |
paul@0 | 54 | specified, use it to write output; otherwise, write output using the |
paul@0 | 55 | request. |
paul@0 | 56 | """ |
paul@0 | 57 | |
paul@1 | 58 | formatFormForOutputType(self.raw, self.request, mimetype, self.attrs, write=write) |
paul@0 | 59 | |
paul@0 | 60 | # Class methods. |
paul@0 | 61 | |
paul@0 | 62 | def getOutputTypes(self): |
paul@0 | 63 | return self.output_mimetypes |
paul@0 | 64 | |
paul@0 | 65 | getOutputTypes = classmethod(getOutputTypes) |
paul@0 | 66 | |
paul@0 | 67 | # vim: tabstop=4 expandtab shiftwidth=4 |