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.2.7, created at 2023-06-07 06:35 +0000

1import abc 

2 

3from ..util import ABC 

4 

5 

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. 

10 

11 transaction isolation is the canonical example, and the 

12 ``IsolationLevelCharacteristic`` implementation provides this for the 

13 ``DefaultDialect``. 

14 

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. 

21 

22 .. versionadded:: 1.4 

23 

24 """ 

25 

26 __slots__ = () 

27 

28 transactional = False 

29 

30 @abc.abstractmethod 

31 def reset_characteristic(self, dialect, dbapi_conn): 

32 """Reset the characteristic on the connection to its default value.""" 

33 

34 @abc.abstractmethod 

35 def set_characteristic(self, dialect, dbapi_conn, value): 

36 """set characteristic on the connection to a given value.""" 

37 

38 @abc.abstractmethod 

39 def get_characteristic(self, dialect, dbapi_conn): 

40 """Given a DBAPI connection, get the current value of the 

41 characteristic. 

42 

43 """ 

44 

45 

46class IsolationLevelCharacteristic(ConnectionCharacteristic): 

47 transactional = True 

48 

49 def reset_characteristic(self, dialect, dbapi_conn): 

50 dialect.reset_isolation_level(dbapi_conn) 

51 

52 def set_characteristic(self, dialect, dbapi_conn, value): 

53 dialect.set_isolation_level(dbapi_conn, value) 

54 

55 def get_characteristic(self, dialect, dbapi_conn): 

56 return dialect.get_isolation_level(dbapi_conn)