util.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3 from importlib import import_module
4 
5 from rosbridge_library.internal import message_conversion
6 
7 
8 def lookup_object(object_path, package='mqtt_bridge'):
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)
13  return obj
14 
15 
17  u""" modify _to_primitive_inst to distinct unicode and str conversion """
19  type_map, primitive_types, string_types, FieldTypeMismatchException,
20  )
21  def _to_primitive_inst(msg, rostype, roottype, stack):
22  # Typecheck the msg
23  msgtype = type(msg)
24  if msgtype in primitive_types and rostype in type_map[msgtype.__name__]:
25  return msg
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
32 
33 
35 extract_values = message_conversion.extract_values
36 populate_instance = message_conversion.populate_instance
37 
38 
39 __all__ = ['lookup_object', 'extract_values', 'populate_instance']
def lookup_object(object_path, package='mqtt_bridge')
Definition: util.py:8
def monkey_patch_message_conversion()
Definition: util.py:16


mqtt_bridge
Author(s): Junya Hayashi
autogenerated on Thu Jun 6 2019 19:18:59