Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import collections
import functools
import typing # noqa: F401
from contextlib import closing
from io import StringIO
from dotmap import DotMap
def empty_str(_):
# type: (typing.Any) -> typing.Text
return ""
DotMap.__str__ = empty_str
def recursive_mapping_iterator(nested_mapping):
# type: (typing.Mapping) -> typing.Generator[typing.Tuple[typing.Text, typing.Any], None, None] # noqa: E501
for key, value in nested_mapping.items():
if isinstance(value, collections.Mapping):
for inner_key, inner_value in recursive_mapping_iterator(value):
yield key + '.' + inner_key, inner_value
else:
yield key, value
def recursive_getattr(obj, attributes):
# type: (typing.Any, typing.Text) -> typing.Any
return functools.reduce(getattr, [obj] + attributes.split('.'))