summaryrefslogtreecommitdiff
path: root/src/mailman/interfaces
diff options
context:
space:
mode:
authorBarry Warsaw2012-03-22 18:29:58 -0400
committerBarry Warsaw2012-03-22 18:29:58 -0400
commitaa2d0ad067adfd2515ed3c256cd0bca296058479 (patch)
tree5aac48ec333bb6c6d69fe53b319e7b53f24483e2 /src/mailman/interfaces
parentae15984804096db593d83740dcd4c158626eb22f (diff)
downloadmailman-aa2d0ad067adfd2515ed3c256cd0bca296058479.tar.gz
mailman-aa2d0ad067adfd2515ed3c256cd0bca296058479.tar.zst
mailman-aa2d0ad067adfd2515ed3c256cd0bca296058479.zip
Several fixes and cleanups, ostensibly to fix Python 2.6 support.
- email.iterators.body_line_iterator() cannot handle unicodes in Python 2.6, because it uses cStringIO.StringIO under the covers, and *that* can't handle unicode. This works fine in Python 2.7, so I override this for the tests only under 2.6 (the code itself isn't affected). - AddressError needs to str() its IAddress attribute explicitly in the __str__() method, otherwise under Python 2.6, you'll get unprintable reprs in the doctests. Again, this works correctly in 2.7, but EIBTI, so it can't hurt either way. - EmailError: a new exception, not related to AddressError. The reason for this it to conform to current nomenclature: "address" means an IAddress while "email" means a text email address. So InvalidEmailAddressError now derives from EmailError instead of AddressError because it gets passed a text email address, and because that is invalid, it never gets turned into an IAddress. The __str__() of this new base exception class does some tricky encoding to keep it compatible between Python 2.6 and 2.7. - UnverifiedAddressError derives from AddressError instead of the more generic MailmanError. - A few random code cleanups are included.
Diffstat (limited to 'src/mailman/interfaces')
-rw-r--r--src/mailman/interfaces/address.py24
-rw-r--r--src/mailman/interfaces/user.py13
2 files changed, 23 insertions, 14 deletions
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):