MCPcopy Index your code
hub / github.com/beetbox/beets / flatten

Function flatten

beetsplug/edit.py:98–120  ·  view source on GitHub ↗

Represent `obj`, a `dbcore.Model` object, as a dictionary for serialization. Only include the given `fields` if provided; otherwise, include everything. The resulting dictionary's keys are strings and the values are safely YAML-serializable types.

(obj, fields)

Source from the content-addressed store, hash-verified

96
97
98def flatten(obj, fields):
99 """Represent `obj`, a `dbcore.Model` object, as a dictionary for
100 serialization. Only include the given `fields` if provided;
101 otherwise, include everything.
102
103 The resulting dictionary's keys are strings and the values are
104 safely YAML-serializable types.
105 """
106 # Format each value.
107 d = {}
108 for key in obj.keys():
109 value = obj[key]
110 if _safe_value(obj, key, value):
111 # A safe value that is faithfully representable in YAML.
112 d[key] = value
113 else:
114 # A value that should be edited as a string.
115 d[key] = obj.formatted()[key]
116
117 # Possibly filter field names.
118 if fields:
119 return {k: v for k, v in d.items() if k in fields}
120 return d
121
122
123def apply_(obj, data):

Callers 1

edit_objectsMethod · 0.85

Calls 4

_safe_valueFunction · 0.85
formattedMethod · 0.80
keysMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected