VMM/Relocated: implemented Relocated.__nonzero__() for truth value testing. v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Thu, 15 Apr 2010 19:46:53 +0000
branchv0.6.x
changeset 249 bb7d9906c529
parent 248 da241eacad4d
child 250 73cd082cd724
VMM/Relocated: implemented Relocated.__nonzero__() for truth value testing. Use EmailAddress' __str__() method when raising RelocatedErrors.
VirtualMailManager/Relocated.py
--- a/VirtualMailManager/Relocated.py	Thu Apr 15 17:10:02 2010 +0000
+++ b/VirtualMailManager/Relocated.py	Thu Apr 15 19:46:53 2010 +0000
@@ -41,6 +41,10 @@
 
         self.__load()
 
+    def __nonzero__(self):
+        """Returns `True` if the Relocated is known, `False` if it's new."""
+        return self._dest is not None
+
     def __load(self):
         """Loads the destination address from the database into the
         `_dest` attribute.
@@ -64,7 +68,7 @@
                        RELOCATED_ADDR_DEST_IDENTICAL)
         if self._dest:
             if self._dest == destination:
-                raise RErr(_(u'The relocated user %r already exists.') %
+                raise RErr(_(u"The relocated user '%s' already exists.") %
                            self._addr, RELOCATED_EXISTS)
             else:
                 self._dest = destination
@@ -86,15 +90,15 @@
     def get_info(self):
         """Returns the address to which mails should be sent."""
         if not self._dest:
-            raise RErr(_(u"The relocated user %r doesn't exist.") %
+            raise RErr(_(u"The relocated user '%s' 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 RErr(_(u"The relocated user %r doesn't exist.") % self._addr,
-                       NO_SUCH_RELOCATED)
+            raise RErr(_(u"The relocated user '%s' doesn't exist.") %
+                       self._addr, NO_SUCH_RELOCATED)
         dbc = self._dbh.cursor()
         dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s",
                     self._gid, self._addr.localpart)