def add_mapping(self, data, name=None):
from .mappings import DocumentObjectField<EOL>from .mappings import NestedObject<EOL>from .mappings import ObjectField<EOL>if isinstance(data, (DocumentObjectField, ObjectField, NestedObject)):<EOL><INDENT>self.mappings[data.name] = data.as_dict()<EOL>return<EOL><DEDENT>if name:<EOL><INDENT>self.mappings[name] = data<EOL>return<EOL>if isinstance(data, dict):<EOL><INDENT>self.mappings.update(data)<EOL><DEDENT>elif isinstance(data, list):<EOL><INDENT>for d in data:<EOL><INDENT>if isinstance(d, dict):<EOL><INDENT>self.mappings.update(d)<EOL><DEDENT>elif isinstance(d, DocumentObjectField):<EOL><INDENT>self.mappings[d.name] = d.as_dict()<EOL><DEDENT>else:<EOL><INDENT>name, data = d<EOL>self.add_mapping(data, name)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Add a new mapping