# HG changeset patch # User Pascal Volk # Date 1250232055 0 # Node ID cb8b2f6a5fca5e49e3eca329ae1fd0a170ffc35e # Parent 766299a8639de097eb3358ffa4920fd0c11f0cfe Transport: converted to new-style class; Domain: query reduction VirtualMailManager/Transport.py: * added: __slots__ * implemented: __eq__(), __ne__() and __str__() VirtualMailManager/Domain.py (updateTransport()): * reduced db lookups/update diff -r 766299a8639d -r cb8b2f6a5fca VirtualMailManager/Domain.py --- a/VirtualMailManager/Domain.py Fri Aug 14 06:16:01 2009 +0000 +++ b/VirtualMailManager/Domain.py Fri Aug 14 06:40:55 2009 +0000 @@ -170,6 +170,8 @@ force -- True/False force new transport for all accounts (bool) """ if self._id > 0: + if transport == self._transport.getTransport(): + return trsp = Transport(self._dbh, transport=transport) dbc = self._dbh.cursor() dbc.execute("UPDATE domain_data SET tid = %s WHERE gid = %s", diff -r 766299a8639d -r cb8b2f6a5fca VirtualMailManager/Transport.py --- a/VirtualMailManager/Transport.py Fri Aug 14 06:16:01 2009 +0000 +++ b/VirtualMailManager/Transport.py Fri Aug 14 06:40:55 2009 +0000 @@ -10,8 +10,9 @@ from Exceptions import VMMTransportException import constants.ERROR as ERR -class Transport: - """A wrapper class thats provide access to the transport table""" +class Transport(object): + """A wrapper class that provides access to the transport table""" + __slots__ = ('__id', '__transport', '_dbh') def __init__(self, dbh, tid=None, transport=None): """Creates a new Transport instance. @@ -38,6 +39,19 @@ self.__transport = transport self._loadByName() + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.__id == other.getID() + return NotImplemented + + def __ne__(self, other): + if isinstance(other, self.__class__): + return self.__id != other.getID() + return NotImplemented + + def __str__(self): + return self.__transport + def _loadByID(self): dbc = self._dbh.cursor() dbc.execute('SELECT transport FROM transport WHERE tid = %s', self.__id)