diff options
Diffstat (limited to 'lib/psycopg1.py')
-rw-r--r-- | lib/psycopg1.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/psycopg1.py b/lib/psycopg1.py index 95b36bf..3808aaa 100644 --- a/lib/psycopg1.py +++ b/lib/psycopg1.py @@ -28,24 +28,26 @@ old code while porting to psycopg 2. Import it as follows:: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. -import psycopg2._psycopg as _2psycopg +import psycopg2._psycopg as _2psycopg # noqa from psycopg2.extensions import cursor as _2cursor from psycopg2.extensions import connection as _2connection -from psycopg2 import * +from psycopg2 import * # noqa import psycopg2.extensions as _ext _2connect = connect + def connect(*args, **kwargs): """connect(dsn, ...) -> new psycopg 1.1.x compatible connection object""" kwargs['connection_factory'] = connection conn = _2connect(*args, **kwargs) conn.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) return conn - + + class connection(_2connection): """psycopg 1.1.x connection.""" - + def cursor(self): """cursor() -> new psycopg 1.1.x compatible cursor object""" return _2connection.cursor(self, cursor_factory=cursor) @@ -56,7 +58,7 @@ class connection(_2connection): self.set_isolation_level(_ext.ISOLATION_LEVEL_AUTOCOMMIT) else: self.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) - + class cursor(_2cursor): """psycopg 1.1.x cursor. @@ -71,25 +73,24 @@ class cursor(_2cursor): for i in range(len(self.description)): res[self.description[i][0]] = row[i] return res - + def dictfetchone(self): row = _2cursor.fetchone(self) if row: return self.__build_dict(row) else: return row - + def dictfetchmany(self, size): res = [] rows = _2cursor.fetchmany(self, size) for row in rows: res.append(self.__build_dict(row)) return res - + def dictfetchall(self): res = [] rows = _2cursor.fetchall(self) for row in rows: res.append(self.__build_dict(row)) return res - |