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.10.6, created at 2025-09-13 11:04 +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 (AllocateIDs, Count, Delete, Get, Put, RunInTransaction, allocate_ids, count, delete, get, put, 

9 run_in_transaction) 

10from .types import (DATASTORE_BASE_TYPES, Entity, KEY_SPECIAL_PROPERTY, Key, QueryDefinition, SortOrder, 

11 current_db_access_log) 

12from .utils import (GetOrInsert, IsInTransaction, acquire_transaction_success_marker, encodeKey, endDataAccessLog, 

13 end_data_access_log, fix_unindexable_properties, get_or_insert, is_in_transaction, keyHelper, 

14 key_helper, normalizeKey, normalize_key, startDataAccessLog, start_data_access_log) 

15 

16__all__ = [ 

17 "KEY_SPECIAL_PROPERTY", 

18 "DATASTORE_BASE_TYPES", 

19 "SortOrder", 

20 "Entity", 

21 "QueryDefinition", 

22 "Key", 

23 "Query", 

24 "fix_unindexable_properties", 

25 "normalizeKey", 

26 "keyHelper", 

27 "Get", 

28 "Count", 

29 "Put", 

30 "Delete", 

31 "RunInTransaction", 

32 "IsInTransaction", 

33 "current_db_access_log", 

34 "GetOrInsert", 

35 "encodeKey", 

36 "acquire_transaction_success_marker", 

37 "AllocateIDs", 

38 "config", 

39 "startDataAccessLog", 

40 "endDataAccessLog", 

41 "cache", 

42 # new exports 

43 "allocate_ids", 

44 "get", 

45 "put", 

46 "is_in_transaction", 

47 "run_in_transaction", 

48 "count", 

49 "get_or_insert", 

50 "normalize_key", 

51 "key_helper", 

52 "start_data_access_log", 

53 "end_data_access_log", 

54 "current_db_access_log", 

55] 

56 

57 

58def __getattr__(attr): 

59 __DEPRECATED_NAMES = { 

60 # stuff prior viur-core < 3.8 

61 "currentDbAccessLog": ("current_db_access_log", current_db_access_log), 

62 } 

63 

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

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

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

67 logging.warning(msg, stacklevel=3) 

68 

69 ret = replace[1] 

70 

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

72 if isinstance(ret, str): 

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

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

75 item = getattr(mod, item) 

76 ret = getattr(item, attr) 

77 

78 return ret 

79 

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