# HG changeset patch # User Paul Boddie # Date 1373474788 -7200 # Node ID 3a244796f64ddd1d0807fa9172f3abc3a7e8362a # Parent 8ec694d6af6b46cb90516460fa5b7f0603a46b98 Removed the parser for encrypted content since MoinShare now decrypts encrypted messages and can format the decrypted content itself. diff -r 8ec694d6af6b -r 3a244796f64d parsers/pgp.py --- a/parsers/pgp.py Wed Jul 10 18:35:38 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -# -*- coding: iso-8859-1 -*- -""" - MoinMoin - pgp (MoinMessage) - - @copyright: 2012, 2013 by Paul Boddie - @license: GNU GPL (v2 or later), see COPYING.txt for details. -""" - -from MoinSupport import parseAttributes -from MoinMessage import GPG, is_signed, is_encrypted, \ - MoinMessageDecodingError, MoinMessageError -from MoinMessageSupport import get_homedir -import email.parser - -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO - -Dependencies = ["pages"] - -# Parser support. - -class Parser: - - """ - Extract information from PGP-encrypted content, subject to key availability. - """ - - Dependencies = Dependencies - extensions = [] - - # Input content types understood by this parser. - - input_mimetypes = ["multipart/encrypted"] - - # Output content types preferred by this parser. - - output_mimetypes = [] - - 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 - attrs = parseAttributes(kw.get("format_args", ""), False) - - self.fragment = attrs.get("fragment") - - def _decrypt(self, text): - - "Decrypt the content." - - homedir = get_homedir(self.request) - gpg = GPG(homedir) - - # Obtain a message from the text. - - message = email.parser.Parser().parse(StringIO(text)) - - # Decrypt the message. - - if is_encrypted(message): - message_text = gpg.decryptMessage(message) - message = email.parser.Parser().parse(StringIO(message_text)) - - # Extract any signature details. - - if is_signed(message): - result = gpg.verifyMessage(message) - if result: - return result - - return None, None, message - - def _decode(self, part): - - "Decode the given 'part'." - - charset = part.get_content_charset() - payload = part.get_payload(decode=True) - return charset and unicode(payload, charset) or payload - - def format(self, fmt, write=None): - - """ - Format content using the given formatter 'fmt'. If the 'write' - parameter is specified, use it to write output; otherwise, write output - using the request. - """ - - write = write or self.request.write - - try: - fingerprint, identity, content = self._decrypt(self.raw) - write(fmt.text(self._decode(content))) - - except MoinMessageDecodingError: - write(fmt.text(_("Encrypted content was improperly encoded."))) - - except MoinMessageError: - write(fmt.text(_("Encrypted content could not be decrypted/verified."))) - - # Extra API methods. - - def formatForOutputType(self, mimetype, write=None): - - """ - Format content for the given 'mimetype'. If the 'write' parameter is - specified, use it to write output; otherwise, write output using the - request. - """ - - self.format(self.request.html_formatter, write) - - # Class methods. - - def getOutputTypes(self): - return self.output_mimetypes - - getOutputTypes = classmethod(getOutputTypes) - -# vim: tabstop=4 expandtab shiftwidth=4