<s> from sqlalchemy . orm . session import Session , sessionmaker <EOL> import transaction <EOL> from sqlalchemy . orm . scoping import scoped_session <EOL> from zope . sqlalchemy . datamanager import ZopeTransactionExtension <EOL> from sqlalchemy . ext . declarative . api import declarative_base <EOL> class MySession ( Session ) : <EOL> """<STR_LIT>""" <EOL> def commit ( self , * args , ** kw ) : <EOL> transaction . commit ( * args , ** kw ) <EOL> def rollback ( self , * args , ** kw ) : <EOL> transaction . abort ( * args , ** kw ) <EOL> DBSession = None <EOL> def init_session ( override_session = None ) : <EOL> global DBSession <EOL> if override_session : <EOL> DBSession = override_session <EOL> else : <EOL> DBSession = scoped_session ( sessionmaker ( extension = ZopeTransactionExtension ( ) , class_ = MySession ) ) <EOL> Base = None <EOL> def init_declarative_base ( override_base = None ) : <EOL> global Base <EOL> if override_base : <EOL> Base = override_base <EOL> else : <EOL> Base = declarative_base ( ) <EOL> def init_db ( engine ) : <EOL> DBSession . configure ( bind = engine ) <EOL> Base . metadata . bind = engine </s>
