mytoolkit/mymanager.py
changeset 16 cb7e13711a99
parent 15 93450b43e627
child 18 a9e12b7cc207
equal deleted inserted replaced
15:93450b43e627 16:cb7e13711a99
    91     def __init__(self, isolation_level=None, init_statement=None, keep_open=1, **kw):
    91     def __init__(self, isolation_level=None, init_statement=None, keep_open=1, **kw):
    92         self.isolation_level = isolation_level
    92         self.isolation_level = isolation_level
    93         self.init_statement = init_statement
    93         self.init_statement = init_statement
    94         self.keep_open = keep_open
    94         self.keep_open = keep_open
    95         self.parameters = kw
    95         self.parameters = kw
       
    96         self.adjust_parameters()
       
    97     
       
    98     def adjust_parameters(self):
       
    99         '''Rename Postgres parameters to proper value for MySQL.'''
       
   100         m = {'dbname' : 'db', 'password' : 'passwd'}
       
   101         res = dict()
       
   102         for k, v in list(self.parameters.items()):
       
   103             if k in m:
       
   104                 k = m[k]
       
   105             res[k] = v
       
   106         self.parameters = res
    96 
   107 
    97 
   108 
    98 class RowDict(dict):
   109 class RowDict(dict):
    99 
   110 
   100     def __getattr__(self, key):
   111     def __getattr__(self, key):
   141 
   152 
   142     def __del__(self):
   153     def __del__(self):
   143         for conn in tuple(self.conn_known.keys()):
   154         for conn in tuple(self.conn_known.keys()):
   144             self.destroy_conn(conn)
   155             self.destroy_conn(conn)
   145 
   156 
   146     def create_conn(self, name='default', isolation_level=None, dsn=None, **kw):
   157     def create_conn(self, name='default', isolation_level=None, **kw):
   147         '''Create named connection.'''
   158         '''Create named connection.'''
   148         if name in self.conn_known:
   159         if name in self.conn_known:
   149             raise MyManagerError('Connection name "%s" already registered.' % name)
   160             raise MyManagerError('Connection name "%s" already registered.' % name)
   150 
   161 
   151         isolation_level = self._normalize_isolation_level(isolation_level)
   162         isolation_level = self._normalize_isolation_level(isolation_level)