# Path: web/py3helpers.py



import datetime
import os
import re
import time
    import urlparse
    import ast
    import sys
            import DBUtils  # noqa, flake8 F401
            import psycopg2.extensions
            import kinterbasdb as db
        import pymssql as db
        import cx_Oracle as db
    import doctest
from .py3helpers import iteritems
from .utils import iters, safestr, safeunicode, storage, threadeddict
    from urllib import parse as urlparse
    from urllib.parse import unquote
    from urllib import unquote
    from .webapi import debug, config
            from DBUtils import PooledDB

        if self.transaction_count:
            # nested transactions are not supported in some databases
            if self.ctx.get("ignore_nested_transactions"):
                self.engine = dummy_engine()
            else:
                self.engine = subtransaction_engine()
        else:
            self.engine = transaction_engine()

        self.engine.do_transact()
        self.ctx.transactions.append(self)

    def __enter__(self):
        return self

    def __exit__(self, exctype, excvalue, traceback):
        if exctype is not None:
            self.rollback()
        else:
            self.commit()

    def commit(self):
        if len(self.ctx.transactions) > self.transaction_count:
            self.engine.do_commit()
            self.ctx.transactions = self.ctx.transactions[: self.transaction_count]

    def rollback(self):
        if len(self.ctx.transactions) > self.transaction_count:
            self.engine.do_rollback()

# Path: web/py3helpers.py



# Path: web/db.py
import datetime
import os
import re
import time
    import urlparse
    import ast
    import sys
            import DBUtils  # noqa, flake8 F401
            import psycopg2.extensions
            import kinterbasdb as db
        import pymssql as db
        import cx_Oracle as db
    import doctest
from .py3helpers import iteritems
from .utils import iters, safestr, safeunicode, storage, threadeddict
    from urllib import parse as urlparse
    from urllib.parse import unquote
    from urllib import unquote
    from .webapi import debug, config
            from DBUtils import PooledDB


        if self.transaction_count:
            # nested transactions are not supported in some databases
            if self.ctx.get("ignore_nested_transactions"):
                self.engine = dummy_engine()
            else:
                self.engine = subtransaction_engine()
        else:
            self.engine = transaction_engine()

        self.engine.do_transact()
        self.ctx.transactions.append(self)

    def __enter__(self):
        return self

    def __exit__(self, exctype, excvalue, traceback):
        if exctype is not None:
            self.rollback()
        else:
            self.commit()

    def commit(self):
        if len(self.ctx.transactions) > self.transaction_count:
            self.engine.do_commit()
            self.ctx.transactions = self.ctx.transactions[: self.transaction_count]

    def rollback(self):
        if len(self.ctx.transactions) > self.transaction_count:
            self.engine.do_rollback()

            self.ctx.transactions = self.ctx.transactions[: self.transaction_count]