VirtualMailManager/serviceset.py
branchv0.7.x
changeset 643 df1e3b67882a
parent 638 0de0b9e75c9f
child 671 a9d86ccac044
equal deleted inserted replaced
642:4cd9d0a9f42f 643:df1e3b67882a
    63         if cfg_dget('misc.dovecot_version') < 0x10200b02:
    63         if cfg_dget('misc.dovecot_version') < 0x10200b02:
    64             self._sieve_col = 'managesieve'
    64             self._sieve_col = 'managesieve'
    65         else:
    65         else:
    66             self._sieve_col = 'sieve'
    66             self._sieve_col = 'sieve'
    67 
    67 
    68         for key in kwargs.iterkeys():
    68         for key in kwargs.keys():
    69             if key not in self.__class__._kwargs:
    69             if key not in self.__class__._kwargs:
    70                 raise ValueError('unrecognized keyword: %r' % key)
    70                 raise ValueError('unrecognized keyword: %r' % key)
    71             if key == 'ssid':
    71             if key == 'ssid':
    72                 assert not isinstance(kwargs[key], bool) and \
    72                 assert not isinstance(kwargs[key], bool) and \
    73                        isinstance(kwargs[key], (int, long)) and kwargs[key] > 0
    73                        isinstance(kwargs[key], int) and kwargs[key] > 0
    74                 self._load_by_ssid(kwargs[key])
    74                 self._load_by_ssid(kwargs[key])
    75                 break
    75                 break
    76             else:
    76             else:
    77                 assert isinstance(kwargs[key], bool)
    77                 assert isinstance(kwargs[key], bool)
    78                 if not kwargs[key]:
    78                 if not kwargs[key]:
    99         else:
    99         else:
   100             return self._services[name]
   100             return self._services[name]
   101 
   101 
   102     def __repr__(self):
   102     def __repr__(self):
   103         return '%s(%s, %s)' % (self.__class__.__name__, self._dbh,
   103         return '%s(%s, %s)' % (self.__class__.__name__, self._dbh,
   104                   ', '.join('%s=%r' % s for s in self._services.iteritems()))
   104                   ', '.join('%s=%r' % s for s in self._services.items()))
   105 
   105 
   106     def _load_by_services(self):
   106     def _load_by_services(self):
   107         """Try to load the service_set by it's service combination."""
   107         """Try to load the service_set by it's service combination."""
   108         sql = ('SELECT ssid FROM service_set WHERE %s' %
   108         sql = ('SELECT ssid FROM service_set WHERE %s' %
   109                ' AND '.join('%s = %s' %
   109                ' AND '.join('%s = %s' %
   110                (k, str(v).upper()) for k, v in self._services.iteritems()))
   110                (k, str(v).upper()) for k, v in self._services.items()))
   111         if self._sieve_col == 'managesieve':
   111         if self._sieve_col == 'managesieve':
   112             sql = sql.replace('sieve', self._sieve_col)
   112             sql = sql.replace('sieve', self._sieve_col)
   113         dbc = self._dbh.cursor()
   113         dbc = self._dbh.cursor()
   114         dbc.execute(sql)
   114         dbc.execute(sql)
   115         result = dbc.fetchone()
   115         result = dbc.fetchone()