VMM/maillocation: MailLocation.__init__(): take a 'format' name,
instead of a 'directory' name.
- added function known_format() to the module.
VMM/Account: Adjusted to above changes.
# -*- coding: UTF-8 -*-# Copyright (c) 2008 - 2010, Pascal Volk# See COPYING for distribution information.""" VirtualMailManager.Transport Virtual Mail Manager's Transport class to manage the transport for domains and accounts."""fromVirtualMailManager.constants.ERRORimportUNKNOWN_TRANSPORT_IDfromVirtualMailManager.errorsimportTransportErrorfromVirtualMailManager.pycompatimportanyclassTransport(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. Either tid or transport must be specified. When both arguments are given, tid will be used. Keyword arguments: dbh -- a pyPgSQL.PgSQL.connection tid -- the id of a transport (int/long) transport -- the value of the transport (str) """self._dbh=dbhassertany((tid,transport))iftid:assertnotisinstance(tid,bool)andisinstance(tid,(int,long))self._id=tidself._loadByID()else:assertisinstance(transport,basestring)self._transport=transportself._loadByName()@propertydefid(self):"""The transport's unique ID."""returnself._id@propertydeftransport(self):"""The transport's value, ex: 'dovecot:'"""returnself._transportdef__eq__(self,other):ifisinstance(other,self.__class__):returnself._id==other.idreturnNotImplementeddef__ne__(self,other):ifisinstance(other,self.__class__):returnself._id!=other.idreturnNotImplementeddef__str__(self):returnself._transportdef_loadByID(self):dbc=self._dbh.cursor()dbc.execute('SELECT transport FROM transport WHERE tid = %s',self._id)result=dbc.fetchone()dbc.close()ifresult:self._transport=result[0]else:raiseTransportError(_('Unknown tid specified.'),UNKNOWN_TRANSPORT_ID)def_loadByName(self):dbc=self._dbh.cursor()dbc.execute('SELECT tid FROM transport WHERE transport = %s',self._transport)result=dbc.fetchone()dbc.close()ifresult:self._id=result[0]else:self._save()def_save(self):dbc=self._dbh.cursor()dbc.execute("SELECT nextval('transport_id')")self._id=dbc.fetchone()[0]dbc.execute('INSERT INTO transport VALUES (%s, %s)',self._id,self._transport)self._dbh.commit()dbc.close()