Commit 59d142fd authored by Vincent Pelletier's avatar Vincent Pelletier

Make storage.database.manager ctor API consistent with its subclasses.

Also, make it call _parse to simplify subclasses.
parent 6b6ab5d1
......@@ -122,7 +122,7 @@ def safeIter(func, *args, **kw):
class BTreeDatabaseManager(DatabaseManager):
def __init__(self, database):
super(BTreeDatabaseManager, self).__init__()
super(BTreeDatabaseManager, self).__init__(database)
self.setup(reset=1)
@property
......
......@@ -25,13 +25,16 @@ class CreationUndone(Exception):
class DatabaseManager(object):
"""This class only describes an interface for database managers."""
def __init__(self):
def __init__(self, database):
"""
Initialize the object.
"""
self._under_transaction = False
self._parse(database)
def _parse(self, database):
"""Called during instanciation, to process database parameter."""
pass
def isUnderTransaction(self):
return self._under_transaction
......
......@@ -56,8 +56,7 @@ class MySQLDatabaseManager(DatabaseManager):
_use_partition = False
def __init__(self, database):
super(MySQLDatabaseManager, self).__init__()
self.user, self.passwd, self.db, self.socket = self._parse(database)
super(MySQLDatabaseManager, self).__init__(database)
self.conn = None
self._config = {}
self._connect()
......@@ -65,8 +64,8 @@ class MySQLDatabaseManager(DatabaseManager):
def _parse(self, database):
""" Get the database credentials (username, password, database) """
# expected pattern : [user[:password]@]database[unix_socket]
return re.match('(?:([^:]+)(?::(.*))?@)?([^./]+)(.+)?$',
database).groups()
self.user, self.passwd, self.db, self.socket = re.match(
'(?:([^:]+)(?::(.*))?@)?([^./]+)(.+)?$', database).groups()
def close(self):
self.conn.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment