VirtualMailManager/Transport.py
changeset 48 0d5f58f8b8f5
parent 47 191d5a5adc4a
child 76 14c0a092d7d2
equal deleted inserted replaced
47:191d5a5adc4a 48:0d5f58f8b8f5
    29         tid -- the id of a transport (long)
    29         tid -- the id of a transport (long)
    30         transport -- the value of the transport (str)
    30         transport -- the value of the transport (str)
    31         """
    31         """
    32         self._dbh = dbh
    32         self._dbh = dbh
    33         if tid is None and transport is None:
    33         if tid is None and transport is None:
    34             raise VMMTransportException((
    34             raise VMMTransportException(
    35                 _('Either tid or transport must be specified.'),
    35                 _('Either tid or transport must be specified.'),
    36                 ERR.TRANSPORT_INIT))
    36                 ERR.TRANSPORT_INIT)
    37         elif tid is not None:
    37         elif tid is not None:
    38             try:
    38             try:
    39                 self.__id = long(tid)
    39                 self.__id = long(tid)
    40             except ValueError:
    40             except ValueError:
    41                 raise VMMTransportException((_('tid must be an int/long.'),
    41                 raise VMMTransportException(_('tid must be an int/long.'),
    42                     ERR.TRANSPORT_INIT))
    42                     ERR.TRANSPORT_INIT)
    43             self._loadByID()
    43             self._loadByID()
    44         else:
    44         else:
    45             self.__transport = transport
    45             self.__transport = transport
    46             self._loadByName()
    46             self._loadByName()
    47 
    47 
    51         result = dbc.fetchone()
    51         result = dbc.fetchone()
    52         dbc.close()
    52         dbc.close()
    53         if result is not None:
    53         if result is not None:
    54             self.__transport = result[0]
    54             self.__transport = result[0]
    55         else:
    55         else:
    56             raise VMMTransportException((_('Unknown tid specified.'),
    56             raise VMMTransportException(_('Unknown tid specified.'),
    57                 ERR.UNKNOWN_TRANSPORT_ID))
    57                 ERR.UNKNOWN_TRANSPORT_ID)
    58 
    58 
    59     def _loadByName(self):
    59     def _loadByName(self):
    60         dbc = self._dbh.cursor()
    60         dbc = self._dbh.cursor()
    61         dbc.execute('SELECT tid FROM transport WHERE transport = %s',
    61         dbc.execute('SELECT tid FROM transport WHERE transport = %s',
    62                 self.__transport)
    62                 self.__transport)