summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/app/registrar.py3
-rw-r--r--src/mailman/app/tests/test_subscriptions.py5
-rw-r--r--src/mailman/email/validate.py4
-rw-r--r--src/mailman/interfaces/address.py24
-rw-r--r--src/mailman/interfaces/user.py13
-rw-r--r--src/mailman/runners/tests/test_confirm.py3
-rw-r--r--src/mailman/runners/tests/test_join.py4
-rw-r--r--src/mailman/testing/helpers.py18
8 files changed, 52 insertions, 22 deletions
diff --git a/src/mailman/app/registrar.py b/src/mailman/app/registrar.py
index b95fda1f8..030a504f7 100644
--- a/src/mailman/app/registrar.py
+++ b/src/mailman/app/registrar.py
@@ -17,7 +17,7 @@
"""Implementation of the IUserRegistrar interface."""
-from __future__ import unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
@@ -27,7 +27,6 @@ __all__ = [
import logging
-from pkg_resources import resource_string
from zope.component import getUtility
from zope.interface import implements
diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py
index 6ab386f7f..a63c9ac04 100644
--- a/src/mailman/app/tests/test_subscriptions.py
+++ b/src/mailman/app/tests/test_subscriptions.py
@@ -17,10 +17,11 @@
"""Tests for the subscription service."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestJoin'
]
@@ -63,6 +64,6 @@ class TestJoin(unittest.TestCase):
try:
self._service.join('test@example.com', 'bogus')
except InvalidEmailAddressError as exc:
- self.assertEqual(exc.address, 'bogus')
+ self.assertEqual(exc.email, 'bogus')
else:
raise AssertionError('InvalidEmailAddressError expected')
diff --git a/src/mailman/email/validate.py b/src/mailman/email/validate.py
index d0df7592f..1861a8121 100644
--- a/src/mailman/email/validate.py
+++ b/src/mailman/email/validate.py
@@ -15,9 +15,9 @@
# You should have received a copy of the GNU General Public License along with
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
-"""Module stuff."""
+"""Email address validation."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
diff --git a/src/mailman/interfaces/address.py b/src/mailman/interfaces/address.py
index 6c371e1c0..cf2c50bf4 100644
--- a/src/mailman/interfaces/address.py
+++ b/src/mailman/interfaces/address.py
@@ -17,13 +17,14 @@
"""Interface for email address related information."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'AddressAlreadyLinkedError',
'AddressError',
'AddressNotLinkedError',
+ 'EmailError',
'ExistingAddressError',
'IAddress',
'IEmailValidator',
@@ -37,15 +38,30 @@ from mailman.interfaces.errors import MailmanError
+class EmailError(MailmanError):
+ """A generic text email address-related error occurred."""
+
+ def __init__(self, email):
+ super(EmailError, self).__init__()
+ self.email = email
+
+ def __str__(self):
+ # This is a workaround for Python 2.6 support. When self.email
+ # contains non-ascii characters, this will cause unprintable output in
+ # doctests. Python 2.7 can handle it but we haven't dropped support
+ # for 2.6 yet.
+ return self.email.encode('us-ascii', 'backslashreplace')
+
+
class AddressError(MailmanError):
- """A general address-related error occurred."""
+ """A generic IAddress-related error occurred."""
def __init__(self, address):
super(AddressError, self).__init__()
self.address = address
def __str__(self):
- return self.address
+ return str(self.address)
class ExistingAddressError(AddressError):
@@ -60,7 +76,7 @@ class AddressNotLinkedError(AddressError):
"""The address is not linked to the user."""
-class InvalidEmailAddressError(AddressError):
+class InvalidEmailAddressError(EmailError):
"""Email address is invalid."""
diff --git a/src/mailman/interfaces/user.py b/src/mailman/interfaces/user.py
index aba9bcbba..8d0cbfb54 100644
--- a/src/mailman/interfaces/user.py
+++ b/src/mailman/interfaces/user.py
@@ -17,7 +17,7 @@
"""Interface describing the basics of a user."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
@@ -28,20 +28,13 @@ __all__ = [
from zope.interface import Interface, Attribute
-from mailman.interfaces.errors import MailmanError
+from mailman.interfaces.address import AddressError
-class UnverifiedAddressError(MailmanError):
+class UnverifiedAddressError(AddressError):
"""Unverified address cannot be used as a user's preferred address."""
- def __init__(self, address):
- super(UnverifiedAddressError, self).__init__()
- self.address = address
-
- def __str__(self):
- return self.address
-
class IUser(Interface):
diff --git a/src/mailman/runners/tests/test_confirm.py b/src/mailman/runners/tests/test_confirm.py
index ea972c17f..d2b24a2d1 100644
--- a/src/mailman/runners/tests/test_confirm.py
+++ b/src/mailman/runners/tests/test_confirm.py
@@ -21,13 +21,13 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestConfirm',
]
import unittest
from datetime import datetime
-from email.iterators import body_line_iterator
from zope.component import getUtility
from mailman.app.lifecycle import create_list
@@ -36,6 +36,7 @@ from mailman.interfaces.registrar import IRegistrar
from mailman.interfaces.usermanager import IUserManager
from mailman.runners.command import CommandRunner
from mailman.testing.helpers import (
+ body_line_iterator,
get_queue_messages,
make_testable_runner,
specialized_message_from_string as mfs)
diff --git a/src/mailman/runners/tests/test_join.py b/src/mailman/runners/tests/test_join.py
index 8cbd8659f..a584fd2c2 100644
--- a/src/mailman/runners/tests/test_join.py
+++ b/src/mailman/runners/tests/test_join.py
@@ -21,12 +21,13 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestJoin',
+ 'TestJoinWithDigests',
]
import unittest
-from email.iterators import body_line_iterator
from zope.component import getUtility
from mailman.app.lifecycle import create_list
@@ -37,6 +38,7 @@ from mailman.interfaces.subscriptions import ISubscriptionService
from mailman.interfaces.usermanager import IUserManager
from mailman.runners.command import CommandRunner
from mailman.testing.helpers import (
+ body_line_iterator,
get_queue_messages,
make_testable_runner,
reset_the_world,
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py
index 58c72d6d9..032b028a9 100644
--- a/src/mailman/testing/helpers.py
+++ b/src/mailman/testing/helpers.py
@@ -1,3 +1,4 @@
+# Copyright (C) 2008-2012 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -22,6 +23,7 @@ __metaclass__ = type
__all__ = [
'LogFileMark',
'TestableMaster',
+ 'body_line_iterator',
'call_api',
'digest_mbox',
'event_subscribers',
@@ -412,3 +414,19 @@ class LogFileMark:
with open(self._filename) as fp:
fp.seek(self._filepos)
return fp.readline()
+
+
+
+# In Python 2.6, body_line_iterator() uses a cStringIO.StringIO() which cannot
+# handle unicode. In Python 2.7 this works fine. I hate version checks but
+# this is the easiest way to handle it. OTOH, we could just use the manual
+# way for all Python versions instead.
+import sys
+if sys.hexversion >= 0x2070000:
+ from email.iterators import body_line_iterator
+else:
+ def body_line_iterator(msg, decode=False):
+ payload = msg.get_payload(decode=decode)
+ bytes_payload = payload.encode('utf-8')
+ for line in bytes_payload.splitlines():
+ yield line