Coverage for /home/runner/work/viur-core/viur-core/viur/src/viur/core/db/__init__.py: 52%

23 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-25 15:02 +0000

1import logging 

2import warnings 

3 

4from . import cache 

5from .config import conf as config 

6from .query import Query 

7# new exports for 3.8 

8from .transport import ( 

9 allocate_ids, 

10 AllocateIDs, 

11 count, 

12 Count, 

13 delete, 

14 Delete, 

15 get, 

16 Get, 

17 MAX_LOOKUP_KEYS, 

18 put, 

19 Put, 

20 run_in_transaction, 

21 RunInTransaction, 

22) 

23from .types import ( 

24 current_db_access_log, 

25 DATASTORE_BASE_TYPES, 

26 Entity, 

27 KEY_SPECIAL_PROPERTY, 

28 Key, 

29 KeyType, 

30 QueryDefinition, 

31 QueryOrder, 

32 SortOrder, 

33) 

34from .utils import ( 

35 acquire_transaction_success_marker, 

36 encodeKey, 

37 end_data_access_log, 

38 endDataAccessLog, 

39 fix_unindexable_properties, 

40 get_or_insert, 

41 GetOrInsert, 

42 is_in_transaction, 

43 IsInTransaction, 

44 key_helper, 

45 keyHelper, 

46 normalize_key, 

47 normalizeKey, 

48 start_data_access_log, 

49 startDataAccessLog, 

50) 

51 

52__all__ = [ 

53 "KEY_SPECIAL_PROPERTY", 

54 "DATASTORE_BASE_TYPES", 

55 "SortOrder", 

56 "QueryOrder", 

57 "Entity", 

58 "QueryDefinition", 

59 "Key", 

60 "KeyType", 

61 "Query", 

62 "fix_unindexable_properties", 

63 "normalizeKey", 

64 "keyHelper", 

65 "Get", 

66 "Count", 

67 "Put", 

68 "Delete", 

69 "RunInTransaction", 

70 "IsInTransaction", 

71 "current_db_access_log", 

72 "GetOrInsert", 

73 "encodeKey", 

74 "acquire_transaction_success_marker", 

75 "AllocateIDs", 

76 "config", 

77 "startDataAccessLog", 

78 "endDataAccessLog", 

79 "cache", 

80 # new exports 

81 "allocate_ids", 

82 "get", 

83 "put", 

84 "delete", 

85 "MAX_LOOKUP_KEYS", 

86 "is_in_transaction", 

87 "run_in_transaction", 

88 "count", 

89 "get_or_insert", 

90 "normalize_key", 

91 "key_helper", 

92 "start_data_access_log", 

93 "end_data_access_log", 

94 "current_db_access_log", 

95] 

96 

97 

98def __getattr__(attr): 

99 __DEPRECATED_NAMES = { 

100 # stuff prior viur-core < 3.8 

101 "currentDbAccessLog": ("current_db_access_log", current_db_access_log), 

102 } 

103 

104 if replace := __DEPRECATED_NAMES.get(attr): 104 ↛ 105line 104 didn't jump to line 105 because the condition on line 104 was never true

105 msg = f"Use of `utils.{attr}` is deprecated; Use `{replace[0]}` instead!" 

106 warnings.warn(msg, DeprecationWarning, stacklevel=3) 

107 logging.warning(msg, stacklevel=3) 

108 

109 ret = replace[1] 

110 

111 # When this is a string, try to resolve by dynamic import 

112 if isinstance(ret, str): 

113 mod, item, attr = ret.rsplit(".", 2) 

114 mod = __import__(mod, fromlist=(item,)) 

115 item = getattr(mod, item) 

116 ret = getattr(item, attr) 

117 

118 return ret 

119 

120 return super(__import__(__name__).__class__).__getattribute__(attr)