VMM: Partial PEP-308-ification. v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Mon, 05 Nov 2012 21:57:37 +0000
branchv0.7.x
changeset 638 0de0b9e75c9f
parent 637 ca6621caff2f
child 639 d50fe67778c6
VMM: Partial PEP-308-ification.
VirtualMailManager/account.py
VirtualMailManager/cli/subcommands.py
VirtualMailManager/config.py
VirtualMailManager/handler.py
VirtualMailManager/password.py
VirtualMailManager/quotalimit.py
VirtualMailManager/serviceset.py
--- a/VirtualMailManager/account.py	Sun Nov 04 18:33:11 2012 +0000
+++ b/VirtualMailManager/account.py	Mon Nov 05 21:57:37 2012 +0000
@@ -86,11 +86,7 @@
             self._uid, _mid, _qid, _ssid, _tid, _note = result
 
             def load_helper(ctor, own, field, dbresult):
-                #  Py25: cur = None if own is None else getattr(own, field)
-                if own is None:
-                    cur = None
-                else:
-                    cur = getattr(own, field)
+                cur = None if own is None else getattr(own, field)
                 if cur != dbresult:
                     kwargs = {field: dbresult}
                     if dbresult is None:
@@ -248,22 +244,15 @@
         self._prepare(MailLocation(self._dbh, mbfmt=cfg_dget('mailbox.format'),
                                    directory=cfg_dget('mailbox.root')))
         dbc = self._dbh.cursor()
-        qid = ssid = tid = None
-        if self._qlimit:
-            qid = self._qlimit.qid
-        if self._services:
-            ssid = self._services.ssid
-        if self._transport:
-            tid = self._transport.tid
         dbc.execute('INSERT INTO users (local_part, passwd, uid, gid, mid, '
                     'qid, ssid, tid, note) '
                     'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)',
                     (self._addr.localpart,
                      pwhash(self._passwd, user=self._addr), self._uid,
-                     self._domain.gid, self._mail.mid, qid, ssid, tid,
-#                     self._qlimit.qid if self._qlimit else None,
-#                     self._services.ssid if self._services else None,
-#                     self._transport.tid if self._transport else None,
+                     self._domain.gid, self._mail.mid,
+                     self._qlimit.qid if self._qlimit else None,
+                     self._services.ssid if self._services else None,
+                     self._transport.tid if self._transport else None,
                      self._note))
         self._dbh.commit()
         dbc.close()
--- a/VirtualMailManager/cli/subcommands.py	Sun Nov 04 18:33:11 2012 +0000
+++ b/VirtualMailManager/cli/subcommands.py	Mon Nov 05 21:57:37 2012 +0000
@@ -959,11 +959,7 @@
         q_usage['percent'] = locale.format('%6.2f', 100. / limit * used, True)
     else:
         q_usage['percent'] = locale.format('%6.2f', 0, True)
-    #  Py25: fmt = format_domain_default if domaindefault else lambda s: s
-    if domaindefault:
-        fmt = format_domain_default
-    else:
-        fmt = lambda s: s
+    fmt = format_domain_default if domaindefault else lambda s: s
     # TP: e.g.: [  0.00%] 21.09 KiB/1.00 GiB
     return fmt(_(u'[%(percent)s%%] %(used)s/%(limit)s') % q_usage)
 
@@ -1054,10 +1050,7 @@
 
 def _print_domain_list(dids, domains, matching):
     """Print a list of (matching) domains/alias domains."""
-    if matching:
-        title = _(u'Matching domains')
-    else:
-        title = _(u'Existing domains')
+    title = _(u'Matching domains') if matching else _(u'Existing domains')
     w_std(title, '-' * len(title))
     if domains:
         for did in dids:
--- a/VirtualMailManager/config.py	Sun Nov 04 18:33:11 2012 +0000
+++ b/VirtualMailManager/config.py	Mon Nov 05 21:57:37 2012 +0000
@@ -246,10 +246,7 @@
           check the value, when `LazyConfig.set()` is called.
         """
         self.__cls = cls
-        if not default is None:  # enforce the type of the default value
-            self.__default = self.__cls(default)
-        else:
-            self.__default = default
+        self.__default = default if default is None else self.__cls(default)
         if not callable(getter):
             raise TypeError('getter has to be a callable, got a %r' %
                             getter.__class__.__name__)
--- a/VirtualMailManager/handler.py	Sun Nov 04 18:33:11 2012 +0000
+++ b/VirtualMailManager/handler.py	Mon Nov 05 21:57:37 2012 +0000
@@ -615,10 +615,7 @@
                 dpattern = parts[1]
                 dlike = dpattern.startswith('%') or dpattern.endswith('%')
 
-                if llike:
-                    checkp = lpattern.strip('%')
-                else:
-                    checkp = lpattern
+                checkp = lpattern.strip('%') if llike else lpattern
                 if len(checkp) > 0 and re.search(RE_LOCALPART, checkp):
                     raise VMMError(_(u"The pattern '%s' contains invalid "
                                      u"characters.") % pattern,
@@ -629,10 +626,7 @@
                 dpattern = parts[0]
                 dlike = dpattern.startswith('%') or dpattern.endswith('%')
 
-            if dlike:
-                checkp = dpattern.strip('%')
-            else:
-                checkp = dpattern
+            checkp = dpattern.strip('%') if dlike else dpattern
             if len(checkp) > 0 and not re.match(RE_DOMAIN_SEARCH, checkp):
                 raise VMMError(_(u"The pattern '%s' contains invalid "
                                  u"characters.") % pattern, DOMAIN_INVALID)
@@ -855,10 +849,8 @@
         if not acc:
             raise VMMError(_(u"The account '%s' does not exist.") %
                            acc.address, NO_SUCH_ACCOUNT)
-        if transport == 'domain':
-            transport = None
-        else:
-            transport = Transport(self._dbh, transport=transport)
+        transport = None if transport == 'domain' \
+                         else Transport(self._dbh, transport=transport)
         acc.update_transport(transport)
 
     def user_services(self, emailaddress, *services):
--- a/VirtualMailManager/password.py	Sun Nov 04 18:33:11 2012 +0000
+++ b/VirtualMailManager/password.py	Mon Nov 05 21:57:37 2012 +0000
@@ -331,10 +331,7 @@
     """
     dcv = cfg_dget('misc.dovecot_version')
     schemes = (k for (k, v) in _scheme_info.iteritems() if v[1] <= dcv)
-    if dcv >= 0x10100a01:
-        encodings = ('.B64', '.BASE64', '.HEX')
-    else:
-        encodings = ()
+    encodings = ('.B64', '.BASE64', '.HEX') if dcv >= 0x10100a01 else ()
     return schemes, encodings
 
 
--- a/VirtualMailManager/quotalimit.py	Sun Nov 04 18:33:11 2012 +0000
+++ b/VirtualMailManager/quotalimit.py	Mon Nov 05 21:57:37 2012 +0000
@@ -52,14 +52,8 @@
         else:
             bytes_, msgs = kwargs.get('bytes'), kwargs.get('messages')
             assert all(isinstance(i, (int, long)) for i in (bytes_, msgs))
-            if bytes_ < 0:
-                self._bytes = -bytes_
-            else:
-                self._bytes = bytes_
-            if msgs < 0:
-                self._messages = -msgs
-            else:
-                self._messages = msgs
+            self._bytes = -bytes_ if bytes_ < 0 else bytes_
+            self._messages = -msgs if msgs < 0 else msgs
             self._load_by_limit()
 
     @property
--- a/VirtualMailManager/serviceset.py	Sun Nov 04 18:33:11 2012 +0000
+++ b/VirtualMailManager/serviceset.py	Mon Nov 05 21:57:37 2012 +0000
@@ -131,10 +131,7 @@
         self._ssid = result[0]
         #self._services.update(zip(SERVICES, result[1:]))
         for key, value in zip(SERVICES, result[1:]):  # pyPgSQL compatible
-            if value:
-                self._services[key] = True
-            else:
-                self._services[key] = False
+            self._services[key] = True if value else False
 
     def _save(self):
         """Store a new service_set in the database."""