Package obitools :: Package obischemas :: Package kb
[hide private]
[frames] | no frames]

Source Code for Package obitools.obischemas.kb

 1  """ 
 2      kb package is devoted to manage access to postgresql database from python 
 3      script 
 4  """ 
 5   
 6   
7 -class Connection(object):
8
9 - def __init__(self):
10 raise RuntimeError('pyROM.KB.Connection is an abstract class')
11
12 - def cursor(self):
13 raise RuntimeError('pyROM.KB.Connection.cursor is an abstract function')
14
15 - def commit(self):
16 raise RuntimeError('pyROM.KB.Connection.commit is an abstract function')
17
18 - def rollback(self):
19 raise RuntimeError('pyROM.KB.Connection.rollback is an abstract function')
20
21 - def __call__(self,query):
22 return self.cursor().execute(query)
23 24
25 -class Cursor(object):
26
27 - def __init__(self,db):
28 raise RuntimeError('pyROM.KB.Cursor is an abstract class')
29
30 - def execute(self,query):
31 raise RuntimeError('pyROM.KB.Cursor.execute is an abstract function')
32 33 __call__=execute
34 35 36 _current_connection = None # Static variable used to store connection to KB 37
38 -def getConnection(*args,**kargs):
39 """ 40 return a connection to the database. 41 When call from database backend no argument are needed. 42 All connection returned by this function 43 """ 44 global _current_connection 45 46 if _current_connection==None or args or kargs : 47 try: 48 from obischemas.kb import backend 49 _current_connection = backend.Connection() 50 except ImportError: 51 from obischemas.kb import extern 52 _current_connection = extern.Connection(*args,**kargs) 53 return _current_connection
54