VMM/Domain: get_gid() return 0 instead of raising an Exception, v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Sun, 28 Feb 2010 20:51:34 +0000
branchv0.6.x
changeset 222 d0c16e70a9fb
parent 221 371ae0b4443d
child 223 5c7b7cbb01cd
VMM/Domain: get_gid() return 0 instead of raising an Exception, if the domain wasn't found in the database.
VirtualMailManager/Alias.py
VirtualMailManager/Domain.py
VirtualMailManager/Handler.py
VirtualMailManager/Relocated.py
--- a/VirtualMailManager/Alias.py	Sat Feb 27 21:36:55 2010 +0000
+++ b/VirtualMailManager/Alias.py	Sun Feb 28 20:51:34 2010 +0000
@@ -12,8 +12,8 @@
 from VirtualMailManager.EmailAddress import EmailAddress
 from VirtualMailManager.errors import AliasError as AErr
 from VirtualMailManager.pycompat import all
-from VirtualMailManager.constants.ERROR import ALIAS_ADDR_DEST_IDENTICAL, \
-     ALIAS_EXCEEDS_EXPANSION_LIMIT, ALIAS_EXISTS, NO_SUCH_ALIAS
+from VirtualMailManager.constants.ERROR import \
+     ALIAS_EXCEEDS_EXPANSION_LIMIT, NO_SUCH_ALIAS, NO_SUCH_DOMAIN
 
 
 _ = lambda msg: msg
@@ -28,6 +28,9 @@
         self._addr = address
         self._dbh = dbh
         self._gid = get_gid(self._dbh, self._addr.domainname)
+        if not self._gid:
+            raise AErr(_(u"The domain %r doesn't exist.") %
+                       self._addr.domainname, NO_SUCH_DOMAIN)
         self._dests = []
 
         self.__load_dests()
--- a/VirtualMailManager/Domain.py	Sat Feb 27 21:36:55 2010 +0000
+++ b/VirtualMailManager/Domain.py	Sun Feb 28 20:51:34 2010 +0000
@@ -313,9 +313,10 @@
     return order, domdict
 
 def get_gid(dbh, domainname):
-    """Returns the *GID* of the domain *domainname*.
+    """Returns the group id of the domain *domainname*.
 
-    Raises an `DomainError` if the domain does not exist.
+    If the domain couldn't be found in the database 0 will be returned.
+
     """
     domainname = check_domainname(domainname)
     dbc = dbh.cursor()
@@ -324,6 +325,4 @@
     dbc.close()
     if gid:
         return gid[0]
-    else:
-        raise DomErr(_(u"The domain ā€œ%sā€ doesn't exist.") % domainname,
-                     NO_SUCH_DOMAIN)
+    return 0
--- a/VirtualMailManager/Handler.py	Sat Feb 27 21:36:55 2010 +0000
+++ b/VirtualMailManager/Handler.py	Sun Feb 28 20:51:34 2010 +0000
@@ -547,16 +547,9 @@
             self.__warnings.append(_('Ignored destination addresses:'))
             self.__warnings.extend(('  * %s' % w for w in warnings))
         for destination in destinations:
-            try:
-                gid = get_gid(self._dbh, destination.domainname)
-            except DomainError, e:
-                if e.code == ERR.NO_SUCH_DOMAIN:
-                    continue
-                else:
-                    raise
-            if gid > 0 and \
-                    (not Handler.accountExists(self._dbh, destination) and
-                     not Handler.aliasExists(self._dbh, destination)):
+            gid = get_gid(self._dbh, destination.domainname)
+            if gid and (not Handler.accountExists(self._dbh, destination) and
+                        not Handler.aliasExists(self._dbh, destination)):
                 self.__warnings.append(
                     _(u"The destination account/alias %r doesn't exist.") %
                                        str(destination))
--- a/VirtualMailManager/Relocated.py	Sat Feb 27 21:36:55 2010 +0000
+++ b/VirtualMailManager/Relocated.py	Sun Feb 28 20:51:34 2010 +0000
@@ -11,7 +11,7 @@
 from VirtualMailManager.Domain import get_gid
 from VirtualMailManager.EmailAddress import EmailAddress
 from VirtualMailManager.errors import RelocatedError as RErr
-from VirtualMailManager.constants.ERROR import \
+from VirtualMailManager.constants.ERROR import NO_SUCH_DOMAIN, \
      NO_SUCH_RELOCATED, RELOCATED_ADDR_DEST_IDENTICAL, RELOCATED_EXISTS
 
 
@@ -34,6 +34,9 @@
         self._addr = address
         self._dbh = dbh
         self._gid = get_gid(self._dbh, self._addr.domainname)
+        if not self._gid:
+            raise RErr(_(u"The domain %r doesn't exist.") %
+                       self._addr.domainname, NO_SUCH_DOMAIN)
         self._dest = None
 
         self.__load()