VirtualMailManager/MailLocation.py
changeset 69 0c124160a991
parent 48 0d5f58f8b8f5
child 76 14c0a092d7d2
equal deleted inserted replaced
68:7ae95b9938c4 69:0c124160a991
    12 __author__ = 'Pascal Volk <p.volk@veb-it.de>'
    12 __author__ = 'Pascal Volk <p.volk@veb-it.de>'
    13 __version__ = VERSION
    13 __version__ = VERSION
    14 __revision__ = 'rev '+'$Rev$'.split()[1]
    14 __revision__ = 'rev '+'$Rev$'.split()[1]
    15 __date__ = '$Date$'.split()[1]
    15 __date__ = '$Date$'.split()[1]
    16 
    16 
       
    17 import re
       
    18 
    17 from Exceptions import VMMMailLocationException as MLE
    19 from Exceptions import VMMMailLocationException as MLE
    18 import constants.ERROR as ERR
    20 import constants.ERROR as ERR
       
    21 
       
    22 RE_MAILLOCATION = """^[\w]{1,20}$"""
    19 
    23 
    20 class MailLocation:
    24 class MailLocation:
    21     """A wrapper class thats provide access to the maillocation table"""
    25     """A wrapper class thats provide access to the maillocation table"""
    22     def __init__(self, dbh, mid=None, maillocation=None):
    26     def __init__(self, dbh, mid=None, maillocation=None):
    23         """Creates a new MailLocation instance.
    27         """Creates a new MailLocation instance.
    38                 self.__id = long(mid)
    42                 self.__id = long(mid)
    39             except ValueError:
    43             except ValueError:
    40                 raise MLE(_('mid must be an int/long.'), ERR.MAILLOCATION_INIT)
    44                 raise MLE(_('mid must be an int/long.'), ERR.MAILLOCATION_INIT)
    41             self._loadByID()
    45             self._loadByID()
    42         else:
    46         else:
    43             self.__maillocation = maillocation
    47             re.compile(RE_MAILLOCATION)
    44             self._loadByName()
    48             if re.match(RE_MAILLOCATION, maillocation):
       
    49                 self.__maillocation = maillocation
       
    50                 self._loadByName()
       
    51             else:
       
    52                 raise MLE(
       
    53                     _(u'Invalid folder name »%s«, it may consist only of\n\
       
    54 1 - 20 single byte characters (A-Z, a-z, 0-9 and _).') % maillocation,
       
    55                         ERR.MAILLOCATION_INIT)
    45 
    56 
    46     def _loadByID(self):
    57     def _loadByID(self):
    47         dbc = self._dbh.cursor()
    58         dbc = self._dbh.cursor()
    48         dbc.execute('SELECT maillocation FROM maillocation WHERE mid = %s',
    59         dbc.execute('SELECT maillocation FROM maillocation WHERE mid = %s',
    49                 self.__id)
    60                 self.__id)