<s> from __future__ import absolute_import <EOL> import psycopg2 as Database <EOL> from django . db . backends . postgresql_psycopg2 . base import DatabaseWrapper <EOL> from . decorators import ( <EOL> capture_transaction_exceptions , auto_reconnect_cursor , <EOL> auto_reconnect_connection , less_shitty_error_messages <EOL> ) <EOL> from . operations import DatabaseOperations <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> class CursorWrapper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , db , cursor ) : <EOL> self . db = db <EOL> self . cursor = cursor <EOL> def __getattr__ ( self , attr ) : <EOL> return getattr ( self . cursor , attr ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . cursor ) <EOL> @ capture_transaction_exceptions <EOL> @ auto_reconnect_cursor <EOL> @ less_shitty_error_messages <EOL> def execute ( self , sql , params = None ) : <EOL> if params is not None : <EOL> return self . cursor . execute ( sql , params ) <EOL> return self . cursor . execute ( sql ) <EOL> @ capture_transaction_exceptions <EOL> @ auto_reconnect_cursor <EOL> @ less_shitty_error_messages <EOL> def executemany ( self , sql , paramlist = ( ) ) : <EOL> return self . cursor . executemany ( sql , paramlist ) <EOL> class DatabaseWrapper ( DatabaseWrapper ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( DatabaseWrapper , self ) . __init__ ( * args , ** kwargs ) <EOL> self . ops = DatabaseOperations ( self ) <EOL> @ auto_reconnect_connection <EOL> def _set_isolation_level ( self , level ) : <EOL> return super ( DatabaseWrapper , self ) . _set_isolation_level ( level ) <EOL> @ auto_reconnect_connection <EOL> def _cursor ( self , * args , ** kwargs ) : <EOL> cursor = super ( DatabaseWrapper , self ) . _cursor ( ) <EOL> return CursorWrapper ( self , cursor ) <EOL> def close ( self , reconnect = False ) : <EOL> """<STR_LIT>""" <EOL> if self . connection is not None : <EOL> if not self . connection . closed : <EOL> try : <EOL> self . connection . close ( ) <EOL> except Database . InterfaceError : <EOL> pass <EOL> self . connection = None </s>
