[FIX] Report: get the wkhtmltopdf version in a cleaner way with a simple regex
[odoo/odoo.git] / openerp / sql_db.py
index c93f4fb..3e40134 100644 (file)
@@ -167,7 +167,7 @@ class Cursor(object):
         self.sql_log_count = 0
         self._closed = True    # avoid the call of close() (by __del__) if an exception
                                 # is raised by any of the following initialisations
-        self._pool = pool
+        self.__pool = pool
         self.dbname = dbname
 
         # Whether to enable snapshot isolation level for this cursor.
@@ -313,7 +313,7 @@ class Cursor(object):
             chosen_template = tools.config['db_template']
             templates_list = tuple(set(['template0', 'template1', 'postgres', chosen_template]))
             keep_in_pool = self.dbname not in templates_list
-            self._pool.give_back(self._cnx, keep_in_pool=keep_in_pool)
+            self.__pool.give_back(self._cnx, keep_in_pool=keep_in_pool)
 
     @check
     def autocommit(self, on):
@@ -386,12 +386,12 @@ class TestCursor(Cursor):
         several requests, and simulates committing, rolling back, and closing.
     """
     def __init__(self, *args, **kwargs):
+        super(TestCursor, self).__init__(*args, **kwargs)
         # in order to simulate commit and rollback, the cursor maintains a
         # savepoint at its last commit
-        super(TestCursor, self).__init__(*args, **kwargs)
-        super(TestCursor, self).execute("SAVEPOINT test_cursor")
+        self.execute("SAVEPOINT test_cursor")
+        # we use a lock to serialize concurrent requests
         self._lock = threading.RLock()
-        self._auto_commit = False
 
     def acquire(self):
         self._lock.acquire()
@@ -399,28 +399,24 @@ class TestCursor(Cursor):
     def release(self):
         self._lock.release()
 
-    def execute(self, *args, **kwargs):
-        super(TestCursor, self).execute(*args, **kwargs)
-        if self._auto_commit:
-            self.commit()
+    def force_close(self):
+        super(TestCursor, self).close()
 
-    def close(self, force=False):
-        self.rollback()                 # for stuff that has not been committed
-        if force:
-            super(TestCursor, self).close()
-        else:
-            self.release()
+    def close(self):
+        if not self._closed:
+            self.rollback()             # for stuff that has not been committed
+        self.release()
 
     def autocommit(self, on):
-        self._auto_commit = on
+        _logger.debug("TestCursor.autocommit(%r) does nothing", on)
 
     def commit(self):
-        super(TestCursor, self).execute("RELEASE SAVEPOINT test_cursor")
-        super(TestCursor, self).execute("SAVEPOINT test_cursor")
+        self.execute("RELEASE SAVEPOINT test_cursor")
+        self.execute("SAVEPOINT test_cursor")
 
     def rollback(self):
-        super(TestCursor, self).execute("ROLLBACK TO SAVEPOINT test_cursor")
-        super(TestCursor, self).execute("SAVEPOINT test_cursor")
+        self.execute("ROLLBACK TO SAVEPOINT test_cursor")
+        self.execute("SAVEPOINT test_cursor")
 
 class PsycoConnection(psycopg2.extensions.connection):
     pass
@@ -542,17 +538,17 @@ class Connection(object):
 
     def __init__(self, pool, dbname):
         self.dbname = dbname
-        self._pool = pool
+        self.__pool = pool
 
     def cursor(self, serialized=True):
         cursor_type = serialized and 'serialized ' or ''
         _logger.debug('create %scursor to %r', cursor_type, self.dbname)
-        return Cursor(self._pool, self.dbname, serialized=serialized)
+        return Cursor(self.__pool, self.dbname, serialized=serialized)
 
     def test_cursor(self, serialized=True):
         cursor_type = serialized and 'serialized ' or ''
         _logger.debug('create test %scursor to %r', cursor_type, self.dbname)
-        return TestCursor(self._pool, self.dbname, serialized=serialized)
+        return TestCursor(self.__pool, self.dbname, serialized=serialized)
 
     # serialized_cursor is deprecated - cursors are serialized by default
     serialized_cursor = cursor