Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/characteristics.py: 84%
19 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
1import abc
3from ..util import ABC
6class ConnectionCharacteristic(ABC):
7 """An abstract base for an object that can set, get and reset a
8 per-connection characteristic, typically one that gets reset when the
9 connection is returned to the connection pool.
11 transaction isolation is the canonical example, and the
12 ``IsolationLevelCharacteristic`` implementation provides this for the
13 ``DefaultDialect``.
15 The ``ConnectionCharacteristic`` class should call upon the ``Dialect`` for
16 the implementation of each method. The object exists strictly to serve as
17 a dialect visitor that can be placed into the
18 ``DefaultDialect.connection_characteristics`` dictionary where it will take
19 effect for calls to :meth:`_engine.Connection.execution_options` and
20 related APIs.
22 .. versionadded:: 1.4
24 """
26 __slots__ = ()
28 transactional = False
30 @abc.abstractmethod
31 def reset_characteristic(self, dialect, dbapi_conn):
32 """Reset the characteristic on the connection to its default value."""
34 @abc.abstractmethod
35 def set_characteristic(self, dialect, dbapi_conn, value):
36 """set characteristic on the connection to a given value."""
38 @abc.abstractmethod
39 def get_characteristic(self, dialect, dbapi_conn):
40 """Given a DBAPI connection, get the current value of the
41 characteristic.
43 """
46class IsolationLevelCharacteristic(ConnectionCharacteristic):
47 transactional = True
49 def reset_characteristic(self, dialect, dbapi_conn):
50 dialect.reset_isolation_level(dbapi_conn)
52 def set_characteristic(self, dialect, dbapi_conn, value):
53 dialect.set_isolation_level(dbapi_conn, value)
55 def get_characteristic(self, dialect, dbapi_conn):
56 return dialect.get_isolation_level(dbapi_conn)