Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _find_encoder(self, obj_type):
for type_, enc in list(iteritems(self._encoders)):
if type(type_) is tuple:
try:
modname, typename = type_
except (TypeError, ValueError):
raise CBOREncodeValueError(
"invalid deferred encoder type {!r} (must be a "
"2-tuple of module name and type name, e.g. "
"('collections', 'defaultdict'))".format(type_))
imported_type = getattr(modules.get(modname), typename, None)
if imported_type is not None:
del self._encoders[type_]
self._encoders[imported_type] = enc
type_ = imported_type
else: # pragma: nocover
continue