VMM/Relocated: small code cleanups and cosmetic. v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Fri, 12 Feb 2010 04:26:30 +0000
branchv0.6.x
changeset 202 43e7c8b440da
parent 201 dbb0f7ed7858
child 203 4d601240b7db
VMM/Relocated: small code cleanups and cosmetic.
VirtualMailManager/Relocated.py
--- a/VirtualMailManager/Relocated.py	Fri Feb 12 04:15:18 2010 +0000
+++ b/VirtualMailManager/Relocated.py	Fri Feb 12 04:26:30 2010 +0000
@@ -28,10 +28,9 @@
 
         Use `setDestination()` to set/update the new address, where the
         user has moved to."""
-        if isinstance(address, EmailAddress):
-            self._addr = address
-        else:
+        if not isinstance(address, EmailAddress):
             raise TypeError("Argument 'address' is not an EmailAddress")
+        self._addr = address
         self._dbh = dbh
         self._gid = get_gid(self._dbh, self._addr.domainname)
         self._dest = None
@@ -53,22 +52,20 @@
     def setDestination(self, destination):
         """Sets/updates the new address of the relocated user."""
         update = False
-        if isinstance(destination, EmailAddress):
-            if self._addr == destination:
-                raise VMMRE(_(u'Address and destination are identical.'),
-                            RELOCATED_ADDR_DEST_IDENTICAL)
-            if self._dest:
-                if self._dest == destination:
-                    raise VMMRE(
-                            _(u'The relocated user “%s” already exists.') %
-                                self._addr, RELOCATED_EXISTS)
-                else:
-                    self._dest = destination
-                    update = True
+        if not isinstance(destination, EmailAddress):
+            raise TypeError("Argument 'destination' is not an EmailAddress")
+        if self._addr == destination:
+            raise VMMRE(_(u'Address and destination are identical.'),
+                        RELOCATED_ADDR_DEST_IDENTICAL)
+        if self._dest:
+            if self._dest == destination:
+                raise VMMRE(_(u'The relocated user %r already exists.') %
+                            self._addr, RELOCATED_EXISTS)
             else:
                 self._dest = destination
+                update = True
         else:
-            raise TypeError("Argument 'destination' is not an EmailAddress")
+            self._dest = destination
 
         dbc = self._dbh.cursor()
         if not update:
@@ -83,16 +80,15 @@
 
     def getInfo(self):
         """Returns the address to which mails should be sent."""
-        if self._dest:
-            return self._dest
-        else:
-            raise VMMRE(_(u"The relocated user “%s” doesn't exist.") %
+        if not self._dest:
+            raise VMMRE(_(u"The relocated user %r doesn't exist.") %
                         self._addr, NO_SUCH_RELOCATED)
+        return self._dest
 
     def delete(self):
         """Deletes the relocated entry from the database."""
         if not self._dest:
-            raise VMMRE(_(u"The relocated user “%s” doesn't exist.") %
+            raise VMMRE(_(u"The relocated user %r doesn't exist.") %
                         self._addr, NO_SUCH_RELOCATED)
         dbc = self._dbh.cursor()
         dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s",