summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-03-06 16:31:03 -0800
committerDylan Baker <dylan@pnwbakers.com>2018-03-06 16:41:51 -0800
commit7e15223274875ea8bfaac5f4ed0b2bef6056bbe8 (patch)
tree3831bef0d1618ade22b9a5752956719f06f833f1
parent9c0cc34b683b5caa01e0f94865df88577694e820 (diff)
drop bytes support from Address
We don't want to be comparing bytes anyway, the decode would use utf-8, and that isn't right. Instead make the caller convert to a str of Address first.
-rw-r--r--alot/account.py16
-rw-r--r--tests/account_test.py12
2 files changed, 4 insertions, 24 deletions
diff --git a/alot/account.py b/alot/account.py
index 6cd78919..461d2bbf 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -102,9 +102,6 @@ class Address(object):
def __str__(self):
return '{}@{}'.format(self.username, self.domainname)
- def __bytes__(self):
- return '{}@{}'.format(self.username, self.domainname).encode('utf-8')
-
def __cmp(self, other, comparitor):
"""Shared helper for rich comparison operators.
@@ -126,11 +123,6 @@ class Address(object):
ouser, odomain = other.split('@')
except ValueError:
ouser, odomain = '', ''
- elif isinstance(other, bytes):
- try:
- ouser, odomain = other.decode('utf-8').split('@')
- except ValueError:
- ouser, odomain = b'', b''
else:
ouser = other.username
odomain = other.domainname
@@ -145,13 +137,13 @@ class Address(object):
comparitor(self.domainname.lower(), odomain.lower()))
def __eq__(self, other):
- if not isinstance(other, (Address, (str, bytes))):
- raise TypeError('Address must be compared to Address, str, or bytes')
+ if not isinstance(other, (Address, str)):
+ raise TypeError('Address must be compared to Address or str')
return self.__cmp(other, operator.eq)
def __ne__(self, other):
- if not isinstance(other, (Address, (str, bytes))):
- raise TypeError('Address must be compared to Address,str, or bytes')
+ if not isinstance(other, (Address, str)):
+ raise TypeError('Address must be compared to Address or str')
# != is the only rich comparitor that cannot be implemented using 'and'
# in self.__cmp, so it's implemented as not ==.
return not self.__cmp(other, operator.eq)
diff --git a/tests/account_test.py b/tests/account_test.py
index 959d4c7c..99df9632 100644
--- a/tests/account_test.py
+++ b/tests/account_test.py
@@ -58,14 +58,6 @@ class TestAddress(unittest.TestCase):
"""Tests for the Address class."""
- def test_constructor_bytes(self):
- with self.assertRaises(AssertionError):
- account.Address(b'username', b'domainname')
-
- def test_from_string_bytes(self):
- with self.assertRaises(AssertionError):
- account.Address.from_string(b'user@example.com')
-
def test_from_string(self):
addr = account.Address.from_string('user@example.com')
self.assertEqual(addr.username, 'user')
@@ -75,10 +67,6 @@ class TestAddress(unittest.TestCase):
addr = account.Address('ušer', 'example.com')
self.assertEqual(str(addr), 'ušer@example.com')
- def test_bytes(self):
- addr = account.Address('ušer', 'example.com')
- self.assertEqual(bytes(addr), 'ušer@example.com'.encode('utf-8'))
-
def test_eq_unicode(self):
addr = account.Address('ušer', 'example.com')
self.assertEqual(addr, 'ušer@example.com')