summaryrefslogtreecommitdiff
path: root/src/mailman/runners/command.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/runners/command.py')
-rw-r--r--src/mailman/runners/command.py34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/mailman/runners/command.py b/src/mailman/runners/command.py
index 3d91f663a..b0775c4f4 100644
--- a/src/mailman/runners/command.py
+++ b/src/mailman/runners/command.py
@@ -17,9 +17,6 @@
"""-request robot command runner."""
-from __future__ import absolute_import, print_function, unicode_literals
-
-__metaclass__ = type
__all__ = [
'CommandRunner',
'Results',
@@ -31,21 +28,20 @@ __all__ = [
# -owner.
import re
+import six
import logging
-from StringIO import StringIO
from email.errors import HeaderParseError
from email.header import decode_header, make_header
from email.iterators import typed_subpart_iterator
-from zope.component import getUtility
-from zope.interface import implementer
-
from mailman.config import config
from mailman.core.i18n import _
from mailman.core.runner import Runner
from mailman.email.message import UserNotification
from mailman.interfaces.command import ContinueProcessing, IEmailResults
from mailman.interfaces.languages import ILanguageManager
+from zope.component import getUtility
+from zope.interface import implementer
NL = '\n'
@@ -76,7 +72,7 @@ class CommandFinder:
# Extract the subject header and do RFC 2047 decoding.
raw_subject = msg.get('subject', '')
try:
- subject = unicode(make_header(decode_header(raw_subject)))
+ subject = str(make_header(decode_header(raw_subject)))
# Mail commands must be ASCII.
self.command_lines.append(subject.encode('us-ascii'))
except (HeaderParseError, UnicodeError, LookupError):
@@ -84,7 +80,7 @@ class CommandFinder:
# subject is a unicode object, convert it to ASCII ignoring all
# bogus characters. Otherwise, there's nothing in the subject
# that we can use.
- if isinstance(raw_subject, unicode):
+ if isinstance(raw_subject, six.text_type):
safe_subject = raw_subject.encode('us-ascii', 'ignore')
self.command_lines.append(safe_subject)
# Find the first text/plain part of the message.
@@ -98,9 +94,9 @@ class CommandFinder:
if part is None:
# There was no text/plain part to be found.
return
- body = part.get_payload(decode=True)
+ body = part.get_payload()
# text/plain parts better have string payloads.
- assert isinstance(body, basestring), 'Non-string decoded payload'
+ assert isinstance(body, six.string_types), 'Non-string decoded payload'
lines = body.splitlines()
# Use no more lines than specified
max_lines = int(config.mailman.email_commands_max_lines)
@@ -118,7 +114,7 @@ class CommandFinder:
# Ensure that all the parts are unicodes. Since we only accept
# ASCII commands and arguments, ignore anything else.
parts = [(part
- if isinstance(part, unicode)
+ if isinstance(part, six.text_type)
else part.decode('ascii', 'ignore'))
for part in parts]
yield parts
@@ -130,20 +126,20 @@ class Results:
"""The email command results."""
def __init__(self, charset='us-ascii'):
- self._output = StringIO()
+ self._output = six.StringIO()
self.charset = charset
print(_("""\
The results of your email command are provided below.
"""), file=self._output)
def write(self, text):
- if not isinstance(text, unicode):
+ if isinstance(text, bytes):
text = text.decode(self.charset, 'ignore')
self._output.write(text)
- def __unicode__(self):
+ def __str__(self):
value = self._output.getvalue()
- assert isinstance(value, unicode), 'Not a unicode: %r' % value
+ assert isinstance(value, six.text_type), 'Not a unicode: %r' % value
return value
@@ -207,12 +203,12 @@ class CommandRunner(Runner):
if status == ContinueProcessing.no:
break
# All done. Strip blank lines and send the response.
- lines = filter(None, (line.strip() for line in finder.command_lines))
+ lines = [line.strip() for line in finder.command_lines if line]
if len(lines) > 0:
print(_('\n- Unprocessed:'), file=results)
for line in lines:
print(line, file=results)
- lines = filter(None, (line.strip() for line in finder.ignored_lines))
+ lines = [line.strip() for line in finder.ignored_lines if line]
if len(lines) > 0:
print(_('\n- Ignored:'), file=results)
for line in lines:
@@ -231,7 +227,7 @@ class CommandRunner(Runner):
# Find a charset for the response body. Try the original message's
# charset first, then ascii, then latin-1 and finally falling back to
# utf-8.
- reply_body = unicode(results)
+ reply_body = str(results)
for charset in (results.charset, 'us-ascii', 'latin-1'):
try:
reply_body.encode(charset)