2 from __future__
import absolute_import
3 from importlib
import import_module
9 """ lookup object from a some.module:object_name specification. """ 10 module_name, obj_name = object_path.split(
":")
11 module = import_module(module_name, package)
12 obj = getattr(module, obj_name)
17 u""" modify _to_primitive_inst to distinct unicode and str conversion """ 19 type_map, primitive_types, string_types, FieldTypeMismatchException,
21 def _to_primitive_inst(msg, rostype, roottype, stack):
24 if msgtype
in primitive_types
and rostype
in type_map[msgtype.__name__]:
26 elif msgtype
is unicode
and rostype
in type_map[msgtype.__name__]:
27 return msg.encode(
"utf-8",
"ignore")
28 elif msgtype
is str
and rostype
in type_map[msgtype.__name__]:
29 return msg.decode(
"utf-8").encode(
"utf-8",
"ignore")
30 raise FieldTypeMismatchException(roottype, stack, rostype, msgtype)
31 message_conversion._to_primitive_inst = _to_primitive_inst
35 extract_values = message_conversion.extract_values
36 populate_instance = message_conversion.populate_instance
39 __all__ = [
'lookup_object',
'extract_values',
'populate_instance']
def lookup_object(object_path, package='mqtt_bridge')
def monkey_patch_message_conversion()