mikrokosmos/objects.py
def recursive_resolve(data, obj, trigger=None, triggers=[]):
    """Recurse through a nested data structure and format strings using attributes of obj and triggers"""

    if isinstance(data, dict):
        if 'triggers' in data:
            return [recursive_resolve(data['triggers'], obj, trigger, triggers) for trigger in triggers]
        return {k: recursive_resolve(v, obj, trigger, triggers) for k, v in data.items()}
    elif isinstance(data, list):
        return [recursive_resolve(i, obj, trigger, triggers) for i in data]
    elif isinstance(data, str):
        if 'self.' in data:
            _, att = data.split('.', 1)
            return getattr(obj, att)
        if 'trigger.' in data:
            _, att = data.split('.', 1)
            return getattr(trigger, att)
        else:
            return data.format(**vars(obj))
    else:
        return data
Recurse through a nested data structure and format strings using attributes of obj and triggers
Recurse through a nested data structure and format strings using attributes of obj and triggers
Recurse through a nested data structure and format strings using attributes of obj and triggers
def recursive_resolve(data, obj, trigger=None, triggers=[]):
    if isinstance(data, dict):
        if 'triggers' in data:
            return [recursive_resolve(data['triggers'], obj, trigger, triggers) for trigger in triggers]
        return {k: recursive_resolve(v, obj, trigger, triggers) for k, v in data.items()}
    elif isinstance(data, list):
        return [recursive_resolve(i, obj, trigger, triggers) for i in data]
    elif isinstance(data, str):
        if 'self.' in data:
            _, att = data.split('.', 1)
            return getattr(obj, att)
        if 'trigger.' in data:
            _, att = data.split('.', 1)
            return getattr(trigger, att)
        else:
            return data.format(**vars(obj))
    else:
        return data
def recursive_resolve ( data , obj , trigger = None , triggers = [ ] ) : if isinstance ( data , dict ) : if 'triggers' in data : return [ recursive_resolve ( data [ 'triggers' ] , obj , trigger , triggers ) for trigger in triggers ] return { k : recursive_resolve ( v , obj , trigger , triggers ) for k , v in data . items ( ) } elif isinstance ( data , list ) : return [ recursive_resolve ( i , obj , trigger , triggers ) for i in data ] elif isinstance ( data , str ) : if 'self.' in data : _ , att = data . split ( '.' , 1 ) return getattr ( obj , att ) if 'trigger.' in data : _ , att = data . split ( '.' , 1 ) return getattr ( trigger , att ) else : return data . format ( ** vars ( obj ) ) else : return data
Recurse through a nested data structure and format strings using attributes of obj and triggers
Recurse through a nested data structure and format strings using attributes of obj and triggers
"""Recurse through a nested data structure and format strings using attributes of obj and triggers"""
data
obj
trigger
triggers