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.13.4, created at 2026-02-25 14:23 +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 put, 

18 Put, 

19 run_in_transaction, 

20 RunInTransaction, 

21) 

22from .types import ( 

23 current_db_access_log, 

24 DATASTORE_BASE_TYPES, 

25 Entity, 

26 KEY_SPECIAL_PROPERTY, 

27 Key, 

28 KeyType, 

29 QueryDefinition, 

30 SortOrder, 

31) 

32from .utils import ( 

33 acquire_transaction_success_marker, 

34 encodeKey, 

35 end_data_access_log, 

36 endDataAccessLog, 

37 fix_unindexable_properties, 

38 get_or_insert, 

39 GetOrInsert, 

40 is_in_transaction, 

41 IsInTransaction, 

42 key_helper, 

43 keyHelper, 

44 normalize_key, 

45 normalizeKey, 

46 start_data_access_log, 

47 startDataAccessLog, 

48) 

49 

50__all__ = [ 

51 "KEY_SPECIAL_PROPERTY", 

52 "DATASTORE_BASE_TYPES", 

53 "SortOrder", 

54 "Entity", 

55 "QueryDefinition", 

56 "Key", 

57 "KeyType", 

58 "Query", 

59 "fix_unindexable_properties", 

60 "normalizeKey", 

61 "keyHelper", 

62 "Get", 

63 "Count", 

64 "Put", 

65 "Delete", 

66 "RunInTransaction", 

67 "IsInTransaction", 

68 "current_db_access_log", 

69 "GetOrInsert", 

70 "encodeKey", 

71 "acquire_transaction_success_marker", 

72 "AllocateIDs", 

73 "config", 

74 "startDataAccessLog", 

75 "endDataAccessLog", 

76 "cache", 

77 # new exports 

78 "allocate_ids", 

79 "get", 

80 "put", 

81 "is_in_transaction", 

82 "run_in_transaction", 

83 "count", 

84 "get_or_insert", 

85 "normalize_key", 

86 "key_helper", 

87 "start_data_access_log", 

88 "end_data_access_log", 

89 "current_db_access_log", 

90] 

91 

92 

93def __getattr__(attr): 

94 __DEPRECATED_NAMES = { 

95 # stuff prior viur-core < 3.8 

96 "currentDbAccessLog": ("current_db_access_log", current_db_access_log), 

97 } 

98 

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

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

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

102 logging.warning(msg, stacklevel=3) 

103 

104 ret = replace[1] 

105 

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

107 if isinstance(ret, str): 

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

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

110 item = getattr(mod, item) 

111 ret = getattr(item, attr) 

112 

113 return ret 

114 

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