VMM:/{Alias,EmailAddress,Relocated}: use assertions for argument checks.
--- a/VirtualMailManager/Alias.py Wed Feb 24 04:01:48 2010 +0000
+++ b/VirtualMailManager/Alias.py Wed Feb 24 05:04:30 2010 +0000
@@ -23,8 +23,7 @@
__slots__ = ('_addr', '_dests', '_gid', '_dbh')
def __init__(self, dbh, address):
- if not isinstance(address, EmailAddress):
- raise TypeError("Argument 'address' is not an EmailAddress")
+ assert isinstance(address, EmailAddress)
self._addr = address
self._dbh = dbh
self._gid = get_gid(self._dbh, self._addr.domainname)
@@ -90,8 +89,7 @@
def addDestination(self, destination, expansion_limit):
"""Adds the ``destination`` `EmailAddress` to the alias."""
- if not isinstance(destination, EmailAddress):
- raise TypeError("Argument 'destination' is not an EmailAddress")
+ assert isinstance(destination, EmailAddress)
if self._addr == destination:
raise VMMAE(_(u"Address and destination are identical."),
ALIAS_ADDR_DEST_IDENTICAL)
@@ -111,8 +109,7 @@
def delDestination(self, destination):
"""Deletes the specified ``destination`` address from the alias."""
- if not isinstance(destination, EmailAddress):
- raise TypeError("Argument 'destination' is not an EmailAddress")
+ assert isinstance(destination, EmailAddress)
if not self._dests:
raise VMMAE(_(u"The alias %r doesn't exist.") % str(self._addr),
NO_SUCH_ALIAS)
--- a/VirtualMailManager/EmailAddress.py Wed Feb 24 04:01:48 2010 +0000
+++ b/VirtualMailManager/EmailAddress.py Wed Feb 24 05:04:30 2010 +0000
@@ -23,9 +23,7 @@
def __init__(self, address):
"""Creates a new instance from the string/unicode ``address``."""
- if not isinstance(address, basestring):
- raise TypeError('address is not a str/unicode object: %r' %
- address)
+ assert isinstance(address, basestring)
self._localpart = None
self._domainname = None
self._chk_address(address)
--- a/VirtualMailManager/Relocated.py Wed Feb 24 04:01:48 2010 +0000
+++ b/VirtualMailManager/Relocated.py Wed Feb 24 05:04:30 2010 +0000
@@ -28,8 +28,7 @@
Use `setDestination()` to set/update the new address, where the
user has moved to."""
- if not isinstance(address, EmailAddress):
- raise TypeError("Argument 'address' is not an EmailAddress")
+ assert isinstance(address, EmailAddress)
self._addr = address
self._dbh = dbh
self._gid = get_gid(self._dbh, self._addr.domainname)
@@ -52,8 +51,7 @@
def setDestination(self, destination):
"""Sets/updates the new address of the relocated user."""
update = False
- if not isinstance(destination, EmailAddress):
- raise TypeError("Argument 'destination' is not an EmailAddress")
+ assert isinstance(destination, EmailAddress)
if self._addr == destination:
raise VMMRE(_(u'Address and destination are identical.'),
RELOCATED_ADDR_DEST_IDENTICAL)