|
14 | 14 | import hashlib |
15 | 15 | from collections import namedtuple |
16 | 16 | import copy |
17 | | -import inspect |
| 17 | +from .utils import method_is_called_from |
18 | 18 |
|
19 | 19 | log = logging.getLogger(sys.modules[__name__].__name__) |
20 | 20 |
|
21 | 21 | KeyValue = namedtuple('KeyValue', 'key value') |
22 | 22 |
|
23 | 23 |
|
24 | | -def get_class_from_stack_frame(frame): |
25 | | - args, _, _, value_dict = inspect.getargvalues(frame) |
26 | | - # we check the first parameter for the frame function is |
27 | | - # named 'self' or 'cls' |
28 | | - if len(args): |
29 | | - if args[0] == 'self': |
30 | | - # in that case, 'self' will be referenced in value_dict |
31 | | - instance = value_dict.get(args[0], None) |
32 | | - if instance: |
33 | | - # return its class |
34 | | - return getattr(instance, '__class__', None) |
35 | | - if args[0] == 'cls': |
36 | | - # return the class |
37 | | - return value_dict.get(args[0], None) |
38 | | - |
39 | | - # return None otherwise |
40 | | - return None |
41 | | - |
42 | | - |
43 | | -def guard_call(allowed_classes, level=1): |
44 | | - """ |
45 | | - Checks if the current method is being called from a method of certain classes. |
46 | | - """ |
47 | | - stack_info = inspect.stack()[level + 1] |
48 | | - frame = stack_info[0] |
49 | | - calling_class = get_class_from_stack_frame(frame) |
50 | | - if calling_class: |
51 | | - for klass in allowed_classes: |
52 | | - if issubclass(calling_class, klass): |
53 | | - return True |
54 | | - return False |
55 | | - |
56 | | - |
57 | 24 | class ConfigCatClient(object): |
58 | 25 | _instances = {} |
59 | 26 |
|
@@ -85,7 +52,7 @@ def __init__(self, |
85 | 52 | sdk_key, |
86 | 53 | options=ConfigCatOptions()): |
87 | 54 |
|
88 | | - if not guard_call([ConfigCatClient]): |
| 55 | + if not method_is_called_from(ConfigCatClient.get): |
89 | 56 | log.warning('ConfigCatClient.__init__() is deprecated. ' |
90 | 57 | 'Create the ConfigCat Client as a Singleton object with `ConfigCatClient.get()` instead') |
91 | 58 |
|
|
0 commit comments