MCPcopy Index your code
hub / github.com/apache/caldera / BaseObject

Class BaseObject

app/utility/base_object.py:4–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2
3
4class BaseObject(BaseWorld):
5
6 schema = None
7 display_schema = None
8 load_schema = None
9
10 def __init__(self):
11 self._access = self.Access.APP
12 self._created = self.get_current_timestamp()
13
14 def match(self, criteria):
15 if not criteria:
16 return self
17 criteria_matches = []
18 for k, v in criteria.items():
19 if type(v) is tuple:
20 for val in v:
21 if getattr(self, k) == val:
22 criteria_matches.append(True)
23 else:
24 if getattr(self, k) == v:
25 criteria_matches.append(True)
26 if len(criteria_matches) >= len(criteria) and all(criteria_matches):
27 return self
28
29 def update(self, field, value):
30 """
31 Updates the given field to the given value as long as the value is not None and the new value is different from
32 the current value. Ignoring None prevents current property values from being overwritten to None if the given
33 property is not intentionally passed back to be updated (example: Agent heartbeat)
34
35 :param field: object property to update
36 :param value: value to update to
37 """
38 if (value is not None) and (value != self.__getattribute__(field)):
39 self.__setattr__(field, value)
40
41 def search_tags(self, value):
42 tags = getattr(self, 'tags', None)
43 if tags and value in tags:
44 return True
45
46 @staticmethod
47 def retrieve(collection, unique):
48 return next((i for i in collection if i.unique == unique), None)
49
50 @staticmethod
51 def hash(s):
52 return s
53
54 @staticmethod
55 def clean(d):
56 for k, v in d.items():
57 if v is None:
58 d[k] = ''
59 return d
60
61 @property

Callers 1

test_replace_app_propsFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_replace_app_propsFunction · 0.72