1.1 --- a/css/moinshare.css Wed Nov 06 14:45:40 2013 +0100
1.2 +++ b/css/moinshare.css Mon Nov 11 23:20:54 2013 +0100
1.3 @@ -57,3 +57,9 @@
1.4 div.moinshare-alternative.moinshare-other:target {
1.5 display: block;
1.6 }
1.7 +
1.8 +/* PGP key information. */
1.9 +
1.10 +table.moinshare-pgp-keys {
1.11 + border: 1px solid black;
1.12 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/parsers/pgp_keys.py Mon Nov 11 23:20:54 2013 +0100
2.3 @@ -0,0 +1,117 @@
2.4 +# -*- coding: iso-8859-1 -*-
2.5 +"""
2.6 + MoinMoin - pgp_keys (MoinShare)
2.7 +
2.8 + @copyright: 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
2.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
2.10 +"""
2.11 +
2.12 +from MoinMessage import GPG, MoinMessageError
2.13 +from MoinMessageSupport import get_homedir
2.14 +from MoinSupport import parseAttributes, escattr
2.15 +
2.16 +Dependencies = ["pages"]
2.17 +
2.18 +# Parser support.
2.19 +
2.20 +class Parser:
2.21 +
2.22 + "Display data in application/pgp-keys format."
2.23 +
2.24 + Dependencies = Dependencies
2.25 + extensions = []
2.26 +
2.27 + # Input content types understood by this parser.
2.28 +
2.29 + input_mimetypes = ["application/pgp-keys"]
2.30 +
2.31 + # Output content types preferred by this parser.
2.32 +
2.33 + output_mimetypes = ["text/html"]
2.34 +
2.35 + def __init__(self, raw, request, **kw):
2.36 +
2.37 + """
2.38 + Initialise the parser with the given 'raw' data, 'request' and any
2.39 + keyword arguments that may have been supplied.
2.40 + """
2.41 +
2.42 + self.raw = raw
2.43 + self.request = request
2.44 + self.attrs = parseAttributes(kw.get("format_args", ""), False)
2.45 +
2.46 + def format(self, fmt, write=None):
2.47 +
2.48 + """
2.49 + Format a table using the given formatter 'fmt'. If the 'write' parameter
2.50 + is specified, use it to write output; otherwise, write output using the
2.51 + request.
2.52 + """
2.53 +
2.54 + (write or self.request.write)(fmt.text(self.raw))
2.55 +
2.56 + # Extra API methods.
2.57 +
2.58 + def formatForOutputType(self, mimetype, write=None):
2.59 +
2.60 + """
2.61 + Format a table for the given 'mimetype'. If the 'write' parameter is
2.62 + specified, use it to write output; otherwise, write output using the
2.63 + request.
2.64 + """
2.65 +
2.66 + request = self.request
2.67 + write = write or request.write
2.68 + fmt = request.html_formatter
2.69 + _ = request.getText
2.70 +
2.71 + if not mimetype == "text/html":
2.72 + return
2.73 +
2.74 + homedir = get_homedir(request)
2.75 + if not homedir:
2.76 + return
2.77 +
2.78 + gpg = GPG(homedir)
2.79 +
2.80 + write(fmt.text(_("This message contains one or more keys.")))
2.81 +
2.82 + write(fmt.rawHTML('<table class="moinshare-pgp-keys" summary="%s">' % escattr(_("A table of keys"))))
2.83 + write(fmt.rawHTML("<thead>"))
2.84 + write(fmt.table_row(on=1))
2.85 + write(fmt.rawHTML("<th>")); write(fmt.text(_("Known"))); write(fmt.rawHTML("</th>"))
2.86 + write(fmt.rawHTML("<th>")); write(fmt.text(_("Identity"))); write(fmt.rawHTML("</th>"))
2.87 + write(fmt.rawHTML("<th>")); write(fmt.text(_("Fingerprint"))); write(fmt.rawHTML("</th>"))
2.88 + write(fmt.table_row(on=0))
2.89 + write(fmt.rawHTML("</thead>"))
2.90 +
2.91 + write(fmt.rawHTML("<tbody>"))
2.92 +
2.93 + for key in gpg.getKeysFromString(self.raw):
2.94 + write(fmt.table_row(on=1))
2.95 + write(fmt.table_cell(on=1))
2.96 + try:
2.97 + gpg.listKeys(key["keyid"])
2.98 + write(fmt.icon("(./)"))
2.99 + write(fmt.text(_("Known")))
2.100 + except MoinMessageError:
2.101 + pass
2.102 + write(fmt.table_cell(on=0))
2.103 + write(fmt.table_cell(on=1))
2.104 + write(fmt.text(key["userid"]))
2.105 + write(fmt.table_cell(on=0))
2.106 + write(fmt.table_cell(on=1))
2.107 + write(fmt.text(key["fingerprint"]))
2.108 + write(fmt.table_cell(on=0))
2.109 + write(fmt.table_row(on=0))
2.110 +
2.111 + write(fmt.rawHTML("</tbody></table>"))
2.112 +
2.113 + # Class methods.
2.114 +
2.115 + def getOutputTypes(self):
2.116 + return self.output_mimetypes
2.117 +
2.118 + getOutputTypes = classmethod(getOutputTypes)
2.119 +
2.120 +# vim: tabstop=4 expandtab shiftwidth=4