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): ...@@ -122,7 +122,7 @@ def safeIter(func, *args, **kw):
class BTreeDatabaseManager(DatabaseManager): class BTreeDatabaseManager(DatabaseManager):
def __init__(self, database): def __init__(self, database):
super(BTreeDatabaseManager, self).__init__() super(BTreeDatabaseManager, self).__init__(database)
self.setup(reset=1) self.setup(reset=1)
@property @property
......
...@@ -25,13 +25,16 @@ class CreationUndone(Exception): ...@@ -25,13 +25,16 @@ class CreationUndone(Exception):
class DatabaseManager(object): class DatabaseManager(object):
"""This class only describes an interface for database managers.""" """This class only describes an interface for database managers."""
def __init__(self, database):
def __init__(self):
""" """
Initialize the object. Initialize the object.
""" """
self._under_transaction = False self._under_transaction = False
self._parse(database)
def _parse(self, database):
"""Called during instanciation, to process database parameter."""
pass
def isUnderTransaction(self): def isUnderTransaction(self):
return self._under_transaction return self._under_transaction
......
...@@ -56,8 +56,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -56,8 +56,7 @@ class MySQLDatabaseManager(DatabaseManager):
_use_partition = False _use_partition = False
def __init__(self, database): def __init__(self, database):
super(MySQLDatabaseManager, self).__init__() super(MySQLDatabaseManager, self).__init__(database)
self.user, self.passwd, self.db, self.socket = self._parse(database)
self.conn = None self.conn = None
self._config = {} self._config = {}
self._connect() self._connect()
...@@ -65,8 +64,8 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -65,8 +64,8 @@ class MySQLDatabaseManager(DatabaseManager):
def _parse(self, database): def _parse(self, database):
""" Get the database credentials (username, password, database) """ """ Get the database credentials (username, password, database) """
# expected pattern : [user[:password]@]database[unix_socket] # expected pattern : [user[:password]@]database[unix_socket]
return re.match('(?:([^:]+)(?::(.*))?@)?([^./]+)(.+)?$', self.user, self.passwd, self.db, self.socket = re.match(
database).groups() '(?:([^:]+)(?::(.*))?@)?([^./]+)(.+)?$', database).groups()
def close(self): def close(self):
self.conn.close() 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