# Path: axiom/errors.py
# class TimeoutError(Exception):
# class BadCredentials(UnauthorizedLogin):
# class NoSuchUser(UnauthorizedLogin):
# class MissingDomainPart(NoSuchUser):
# class DuplicateUser(Exception):
# class CannotOpenStore(RuntimeError):
# class NoUpgradePathAvailable(CannotOpenStore):
# class NoCrossStoreReferences(AttributeError):
# class SQLError(RuntimeError):
# class TableAlreadyExists(SQLError):
# class UnknownItemType(Exception):
# class SQLWarning(Warning):
# class TableCreationConcurrencyError(RuntimeError):
# class DuplicateUniqueItem(KeyError):
# class ItemNotFound(KeyError):
# class ItemClassesOnly(TypeError):
# class ChangeRejected(Exception):
# class DependencyError(Exception):
# class DeletionDisallowed(ValueError):
# class DataIntegrityError(RuntimeError):
# class BrokenReference(DataIntegrityError):
# class UpgraderRecursion(RuntimeError):
# class ItemUpgradeError(RuntimeError):
# class UnsatisfiedRequirement(AttributeError):
#     def __init__(self, statement, timeout, underlying):
#     def __init__(self, sql, args, underlying):
#     def __str__(self):
#     def __init__(self, originalFailure, storeID, oldType, newType):
# 
# Path: axiom/iaxiom.py
# class IStatEvent(Interface):
# class IAtomicFile(Interface):
# class IAxiomaticCommand(Interface):
# class IBeneficiary(Interface):
# class IPowerupIndirector(Interface):
# class IScheduler(Interface):
# class IQuery(Interface):
# class IColumn(Interface):
# class IOrdering(Interface):
# class IComparison(Interface):
# class IReliableListener(Interface):
# class IBatchProcessor(Interface):
# class IBatchService(Interface):
# class IVersion(Interface):
#     def __init__(tempname, destdir):
#     def tell():
#     def write(bytes):
#     def close(callback):
#     def abort():
#     def powerUp(implementor, interface):
#     def indirect(interface):
#     def schedule(runnable, when):
#     def __iter__():
#     def count():
#     def cloneQuery(limit):
#     def getShortColumnName(store):
#     def getColumnName(store):
#     def fullyQualifiedName():
#     def __get__(row):
#     def orderColumns():
#     def getInvolvedTables():
#     def getQuery(store):
#     def getArgs(store):
#     def processItem(item):
#     def suspend():
#     def resume():
#     def addReliableListener(listener, style=LOCAL):
#     def removeReliableListener(listener):
#     def getReliableListeners():
#     def start():
#     def suspend(storeID):
#     def resume(storeID):
# LOCAL, REMOTE = list(range(2))


import time, sys
        import sqlite3 as dbapi2
    from pysqlite2 import dbapi2
from twisted.python import log
from axiom import errors, iaxiom
                    # Since attempting to acquire the lock is a fairly cheap
                    # operation, we take another route.  SQLite3 is always told
                    # to use a timeout of 0 - ie, acquire it on the first try
                    # or fail instantly.  We will keep doing this, ten times a
                    # second, until the actual timeout expires.

                    # What would be really fantastic is a notification
                    # mechanism for information about the state of the lock
                    # changing.  Of course this clearly insane, no one has ever
                    # managed to invent a tool for communicating one bit of
                    # information between multiple processes.
                    while 1:
                        try:
                            return self._cursor.execute(sql, args)
                        except dbapi2.OperationalError as e:
                            if e.args[0] == 'database is locked':
                                now = self.time()
                                if self.timeout is not None:
                                    if (now - t) > self.timeout:
                                        raise errors.TimeoutError(sql, self.timeout, e)
                                self.sleep(0.1)
                                blockedTime = self.time() - t
                            else:
                                raise
                finally:
                    txntime = self.time() - t
                    if txntime - blockedTime > 2.0:
                        log.msg('Extremely long execute: %s' % (txntime - blockedTime,))
                        log.msg(sql)
                        # import traceback; traceback.print_stack()

# Path: axiom/errors.py
# class TimeoutError(Exception):
# class BadCredentials(UnauthorizedLogin):
# class NoSuchUser(UnauthorizedLogin):
# class MissingDomainPart(NoSuchUser):
# class DuplicateUser(Exception):
# class CannotOpenStore(RuntimeError):
# class NoUpgradePathAvailable(CannotOpenStore):
# class NoCrossStoreReferences(AttributeError):
# class SQLError(RuntimeError):
# class TableAlreadyExists(SQLError):
# class UnknownItemType(Exception):
# class SQLWarning(Warning):
# class TableCreationConcurrencyError(RuntimeError):
# class DuplicateUniqueItem(KeyError):
# class ItemNotFound(KeyError):
# class ItemClassesOnly(TypeError):
# class ChangeRejected(Exception):
# class DependencyError(Exception):
# class DeletionDisallowed(ValueError):
# class DataIntegrityError(RuntimeError):
# class BrokenReference(DataIntegrityError):
# class UpgraderRecursion(RuntimeError):
# class ItemUpgradeError(RuntimeError):
# class UnsatisfiedRequirement(AttributeError):
#     def __init__(self, statement, timeout, underlying):
#     def __init__(self, sql, args, underlying):
#     def __str__(self):
#     def __init__(self, originalFailure, storeID, oldType, newType):
# 
# Path: axiom/iaxiom.py
# class IStatEvent(Interface):
# class IAtomicFile(Interface):
# class IAxiomaticCommand(Interface):
# class IBeneficiary(Interface):
# class IPowerupIndirector(Interface):
# class IScheduler(Interface):
# class IQuery(Interface):
# class IColumn(Interface):
# class IOrdering(Interface):
# class IComparison(Interface):
# class IReliableListener(Interface):
# class IBatchProcessor(Interface):
# class IBatchService(Interface):
# class IVersion(Interface):
#     def __init__(tempname, destdir):
#     def tell():
#     def write(bytes):
#     def close(callback):
#     def abort():
#     def powerUp(implementor, interface):
#     def indirect(interface):
#     def schedule(runnable, when):
#     def __iter__():
#     def count():
#     def cloneQuery(limit):
#     def getShortColumnName(store):
#     def getColumnName(store):
#     def fullyQualifiedName():
#     def __get__(row):
#     def orderColumns():
#     def getInvolvedTables():
#     def getQuery(store):
#     def getArgs(store):
#     def processItem(item):
#     def suspend():
#     def resume():
#     def addReliableListener(listener, style=LOCAL):
#     def removeReliableListener(listener):
#     def getReliableListeners():
#     def start():
#     def suspend(storeID):
#     def resume(storeID):
# LOCAL, REMOTE = list(range(2))


# Path: axiom/_pysqlite2.py
import time, sys
        import sqlite3 as dbapi2
    from pysqlite2 import dbapi2
from twisted.python import log
from axiom import errors, iaxiom

                    # Since attempting to acquire the lock is a fairly cheap
                    # operation, we take another route.  SQLite3 is always told
                    # to use a timeout of 0 - ie, acquire it on the first try
                    # or fail instantly.  We will keep doing this, ten times a
                    # second, until the actual timeout expires.

                    # What would be really fantastic is a notification
                    # mechanism for information about the state of the lock
                    # changing.  Of course this clearly insane, no one has ever
                    # managed to invent a tool for communicating one bit of
                    # information between multiple processes.
                    while 1:
                        try:
                            return self._cursor.execute(sql, args)
                        except dbapi2.OperationalError as e:
                            if e.args[0] == 'database is locked':
                                now = self.time()
                                if self.timeout is not None:
                                    if (now - t) > self.timeout:
                                        raise errors.TimeoutError(sql, self.timeout, e)
                                self.sleep(0.1)
                                blockedTime = self.time() - t
                            else:
                                raise
                finally:
                    txntime = self.time() - t
                    if txntime - blockedTime > 2.0:
                        log.msg('Extremely long execute: %s' % (txntime - blockedTime,))
                        log.msg(sql)
                        # import traceback; traceback.print_stack()

                    log.msg(interface=iaxiom.IStatEvent,