-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from groove-x/feature/python3
Port from Python 2 to Python 3
- Loading branch information
Showing
14 changed files
with
69 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
inject>=3.3.1,<4.0 | ||
inject>=4.0 | ||
msgpack-python>=0.4.8 | ||
paho-mqtt>=1.2 | ||
pymongo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
from importlib import import_module | ||
from typing import Any, Callable, Dict | ||
|
||
import rospy | ||
from rosbridge_library.internal import message_conversion | ||
|
||
|
||
def lookup_object(object_path, package='mqtt_bridge'): | ||
def lookup_object(object_path: str, package: str='mqtt_bridge') -> Any: | ||
""" lookup object from a some.module:object_name specification. """ | ||
module_name, obj_name = object_path.split(":") | ||
module = import_module(module_name, package) | ||
obj = getattr(module, obj_name) | ||
return obj | ||
|
||
|
||
def monkey_patch_message_conversion(): | ||
u""" modify _to_primitive_inst to distinct unicode and str conversion """ | ||
from rosbridge_library.internal.message_conversion import ( | ||
type_map, primitive_types, string_types, FieldTypeMismatchException, | ||
) | ||
def _to_primitive_inst(msg, rostype, roottype, stack): | ||
# Typecheck the msg | ||
msgtype = type(msg) | ||
if msgtype in primitive_types and rostype in type_map[msgtype.__name__]: | ||
return msg | ||
elif msgtype is unicode and rostype in type_map[msgtype.__name__]: | ||
return msg.encode("utf-8", "ignore") | ||
elif msgtype is str and rostype in type_map[msgtype.__name__]: | ||
return msg.decode("utf-8").encode("utf-8", "ignore") | ||
raise FieldTypeMismatchException(roottype, stack, rostype, msgtype) | ||
message_conversion._to_primitive_inst = _to_primitive_inst | ||
|
||
|
||
monkey_patch_message_conversion() | ||
extract_values = message_conversion.extract_values | ||
populate_instance = message_conversion.populate_instance | ||
extract_values = message_conversion.extract_values # type: Callable[[rospy.Message], Dict] | ||
populate_instance = message_conversion.populate_instance # type: Callable[[Dict, rospy.Message], rospy.Message] | ||
|
||
|
||
__all__ = ['lookup_object', 'extract_values', 'populate_instance'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters