summaryrefslogtreecommitdiff
path: root/alot/account.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-02-21 09:13:05 -0800
committerDylan Baker <dylan@pnwbakers.com>2018-03-01 10:34:56 -0800
commitd61975d90f6cb5372c9973fa6cec340aed0b1502 (patch)
treed7005abca4632a6be31d08340ce6182fe2f468ed /alot/account.py
parent6f504afe0bfd3111e0893d7ce6786316b6ebac04 (diff)
fix account.py
Diffstat (limited to 'alot/account.py')
-rw-r--r--alot/account.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/alot/account.py b/alot/account.py
index c672686d..03f65561 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -65,16 +65,16 @@ class Address(object):
usage treat user names as case-insensitve. Therefore we also, by default,
treat the user name as case insenstive.
- :param unicode user: The "user name" portion of the address.
- :param unicode domain: The domain name portion of the address.
+ :param str user: The "user name" portion of the address.
+ :param str domain: The domain name portion of the address.
:param bool case_sensitive: If False (the default) the user name portion of
the address will be compared to the other user name portion without
regard to case. If True then it will.
"""
def __init__(self, user, domain, case_sensitive=False):
- assert isinstance(user, unicode), 'Username must be unicode'
- assert isinstance(domain, unicode), 'Domain name must be unicode'
+ assert isinstance(user, str), 'Username must be str'
+ assert isinstance(domain, str), 'Domain name must be str'
self.username = user
self.domainname = domain
self.case_sensitive = case_sensitive
@@ -83,27 +83,27 @@ class Address(object):
def from_string(cls, address, case_sensitive=False):
"""Alternate constructor for building from a string.
- :param unicode address: An email address in <user>@<domain> form
+ :param str address: An email address in <user>@<domain> form
:param bool case_sensitive: passed directly to the constructor argument
of the same name.
:returns: An account from the given arguments
:rtype: :class:`Account`
"""
- assert isinstance(address, unicode), 'address must be unicode'
- username, domainname = address.split(u'@')
+ assert isinstance(address, str), 'address must be str'
+ username, domainname = address.split('@')
return cls(username, domainname, case_sensitive=case_sensitive)
def __repr__(self):
- return u'Address({!r}, {!r}, case_sensitive={})'.format(
+ return 'Address({!r}, {!r}, case_sensitive={})'.format(
self.username,
self.domainname,
- unicode(self.case_sensitive))
-
- def __unicode__(self):
- return u'{}@{}'.format(self.username, self.domainname)
+ str(self.case_sensitive))
def __str__(self):
- return u'{}@{}'.format(self.username, self.domainname).encode('utf-8')
+ 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.
@@ -113,24 +113,24 @@ class Address(object):
If the username is not considered case sensitive then lower the
username of both self and the other, and handle that the other can be
- either another :class:`~alot.account.Address`, or a `unicode` instance.
+ either another :class:`~alot.account.Address`, or a `str` instance.
:param other: The other address to compare against
- :type other: unicode or ~alot.account.Address
+ :type other: str or ~alot.account.Address
:param callable comparitor: A function with the a signature
- (unicode, unicode) -> bool that will compare the two instance.
+ (str, str) -> bool that will compare the two instance.
The intention is to use functions from the operator module.
"""
- if isinstance(other, unicode):
+ if isinstance(other, str):
try:
- ouser, odomain = other.split(u'@')
+ ouser, odomain = other.split('@')
except ValueError:
- ouser, odomain = u'', u''
- elif isinstance(other, str):
+ ouser, odomain = '', ''
+ elif isinstance(other, bytes):
try:
- ouser, odomain = other.decode('utf-8').split(u'@')
+ ouser, odomain = other.decode('utf-8').split('@')
except ValueError:
- ouser, odomain = '', ''
+ ouser, odomain = b'', b''
else:
ouser = other.username
odomain = other.domainname
@@ -145,13 +145,13 @@ class Address(object):
comparitor(self.domainname.lower(), odomain.lower()))
def __eq__(self, other):
- if not isinstance(other, (Address, basestring)):
- raise TypeError('Address must be compared to Address or basestring')
+ if not isinstance(other, (Address, (str, bytes))):
+ raise TypeError('Address must be compared to Address, str, or bytes')
return self.__cmp(other, operator.eq)
def __ne__(self, other):
- if not isinstance(other, (Address, basestring)):
- raise TypeError('Address must be compared to Address or basestring')
+ if not isinstance(other, (Address, (str, bytes))):
+ raise TypeError('Address must be compared to Address,str, or bytes')
# != 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)