VMM:/{Alias,EmailAddress,Relocated}: use assertions for argument checks. v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Wed, 24 Feb 2010 05:04:30 +0000
branchv0.6.x
changeset 213 1a9fee6b93bc
parent 212 77ac6f572855
child 214 84e6e898e6c5
VMM:/{Alias,EmailAddress,Relocated}: use assertions for argument checks.
VirtualMailManager/Alias.py
VirtualMailManager/EmailAddress.py
VirtualMailManager/Relocated.py
--- 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)