equal
deleted
inserted
replaced
4 |
4 |
5 """Virtual Mail Manager's Transport class to manage the transport for |
5 """Virtual Mail Manager's Transport class to manage the transport for |
6 domains and accounts.""" |
6 domains and accounts.""" |
7 |
7 |
8 import VirtualMailManager.constants.ERROR as ERR |
8 import VirtualMailManager.constants.ERROR as ERR |
9 from VirtualMailManager.Exceptions import VMMTransportException |
9 from VirtualMailManager.errors import TransportError |
10 |
10 |
11 class Transport(object): |
11 class Transport(object): |
12 """A wrapper class that provides access to the transport table""" |
12 """A wrapper class that provides access to the transport table""" |
13 __slots__ = ('__id', '__transport', '_dbh') |
13 __slots__ = ('__id', '__transport', '_dbh') |
14 def __init__(self, dbh, tid=None, transport=None): |
14 def __init__(self, dbh, tid=None, transport=None): |
21 tid -- the id of a transport (long) |
21 tid -- the id of a transport (long) |
22 transport -- the value of the transport (str) |
22 transport -- the value of the transport (str) |
23 """ |
23 """ |
24 self._dbh = dbh |
24 self._dbh = dbh |
25 if tid is None and transport is None: |
25 if tid is None and transport is None: |
26 raise VMMTransportException( |
26 raise TransportError( |
27 _('Either tid or transport must be specified.'), |
27 _('Either tid or transport must be specified.'), |
28 ERR.TRANSPORT_INIT) |
28 ERR.TRANSPORT_INIT) |
29 elif tid is not None: |
29 elif tid is not None: |
30 try: |
30 try: |
31 self.__id = long(tid) |
31 self.__id = long(tid) |
32 except ValueError: |
32 except ValueError: |
33 raise VMMTransportException(_('tid must be an int/long.'), |
33 raise TransportError(_('tid must be an int/long.'), |
34 ERR.TRANSPORT_INIT) |
34 ERR.TRANSPORT_INIT) |
35 self._loadByID() |
35 self._loadByID() |
36 else: |
36 else: |
37 self.__transport = transport |
37 self.__transport = transport |
38 self._loadByName() |
38 self._loadByName() |
56 result = dbc.fetchone() |
56 result = dbc.fetchone() |
57 dbc.close() |
57 dbc.close() |
58 if result is not None: |
58 if result is not None: |
59 self.__transport = result[0] |
59 self.__transport = result[0] |
60 else: |
60 else: |
61 raise VMMTransportException(_('Unknown tid specified.'), |
61 raise TransportError(_('Unknown tid specified.'), |
62 ERR.UNKNOWN_TRANSPORT_ID) |
62 ERR.UNKNOWN_TRANSPORT_ID) |
63 |
63 |
64 def _loadByName(self): |
64 def _loadByName(self): |
65 dbc = self._dbh.cursor() |
65 dbc = self._dbh.cursor() |
66 dbc.execute('SELECT tid FROM transport WHERE transport = %s', |
66 dbc.execute('SELECT tid FROM transport WHERE transport = %s', |