kopia lustrzana https://github.com/dsblank/activitypub
Fixing bugs in himBHsvar replace
rodzic
ae531ba49b
commit
a7677a27ee
|
@ -349,7 +349,7 @@ class Manager():
|
||||||
self.build_dependencies_from_item(key, s)
|
self.build_dependencies_from_item(key, s)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def replace_items_in_dict(self, dictionary, obj):
|
def replace_in_item(self, item, obj):
|
||||||
"""
|
"""
|
||||||
Replace the "$x" in {"val": "$x"} with self.ap_x
|
Replace the "$x" in {"val": "$x"} with self.ap_x
|
||||||
|
|
||||||
|
@ -359,16 +359,24 @@ class Manager():
|
||||||
>>> n.ap_y = 43
|
>>> n.ap_y = 43
|
||||||
>>> dictionary = {"key1": {"val": "$x"},
|
>>> dictionary = {"key1": {"val": "$x"},
|
||||||
... "key2": {"key3": "$y"}}
|
... "key2": {"key3": "$y"}}
|
||||||
>>> manager.replace_items_in_dict(dictionary, n)
|
>>> retval = manager.replace_in_item(dictionary, n)
|
||||||
>>> dictionary
|
>>> dictionary
|
||||||
{'key1': {'val': 41}, 'key2': {'key3': 43}}
|
{'key1': {'val': 41}, 'key2': {'key3': 43}}
|
||||||
"""
|
"""
|
||||||
for key in dictionary:
|
if isinstance(item, (bool, int, float)):
|
||||||
if isinstance(dictionary[key], str):
|
return item
|
||||||
if dictionary[key].startswith("$"):
|
elif isinstance(item, str):
|
||||||
dictionary[key] = getattr(obj, "ap_" + dictionary[key][1:])
|
return self.expand_defaults(item, obj)
|
||||||
elif isinstance(dictionary[key], dict):
|
elif isinstance(item, dict):
|
||||||
self.replace_items_in_dict(dictionary[key], obj)
|
for key in item:
|
||||||
|
item[key] = self.replace_in_item(item[key], obj)
|
||||||
|
return item
|
||||||
|
elif isinstance(item, list):
|
||||||
|
for i in range(len(item)):
|
||||||
|
item[i] = self.replace_in_item(item[i], obj)
|
||||||
|
return item
|
||||||
|
else:
|
||||||
|
raise Exception("unknown item: %s" % item)
|
||||||
|
|
||||||
def get_item_from_dotted(self, dotted_word, obj):
|
def get_item_from_dotted(self, dotted_word, obj):
|
||||||
"""
|
"""
|
||||||
|
@ -412,9 +420,9 @@ class Manager():
|
||||||
raise Exception("variable depends on field that is empty: %s" % attr_name)
|
raise Exception("variable depends on field that is empty: %s" % attr_name)
|
||||||
if isinstance(attr, str) and "$" in attr:
|
if isinstance(attr, str) and "$" in attr:
|
||||||
setattr(obj, attr_name, self.expand_defaults(attr, obj))
|
setattr(obj, attr_name, self.expand_defaults(attr, obj))
|
||||||
elif isinstance(attr, dict):
|
elif isinstance(attr, (dict, list)):
|
||||||
## traverse dict recursively, looking for replacements:
|
## traverse dict recursively, looking for replacements:
|
||||||
self.replace_items_in_dict(attr, obj)
|
self.replace_in_item(attr, obj)
|
||||||
|
|
||||||
def fill_in_defaults(self, obj):
|
def fill_in_defaults(self, obj):
|
||||||
# Next, fill in field-defaults:
|
# Next, fill in field-defaults:
|
||||||
|
|
Ładowanie…
Reference in New Issue