From a2f01492dbb7a58b896ef36123001dba088dc35b Mon Sep 17 00:00:00 2001 From: Junya Hayashi Date: Mon, 20 Nov 2017 18:41:30 +0900 Subject: [PATCH] Raise if inappropriate bson module is installed (Appease #198) (#270) * Raise Exception if inappropriate bson module is installed (Related to #198) --- .../rosbridge_library/internal/message_conversion.py | 3 +-- rosbridge_library/src/rosbridge_library/protocol.py | 3 +-- .../src/rosbridge_library/util/__init__.py | 10 ++++++++++ rosbridge_server/src/rosbridge_server/udp_handler.py | 3 +-- .../src/rosbridge_server/websocket_handler.py | 3 +-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/rosbridge_library/src/rosbridge_library/internal/message_conversion.py b/rosbridge_library/src/rosbridge_library/internal/message_conversion.py index c315588cb..31ded83bf 100644 --- a/rosbridge_library/src/rosbridge_library/internal/message_conversion.py +++ b/rosbridge_library/src/rosbridge_library/internal/message_conversion.py @@ -41,9 +41,8 @@ import re import string from base64 import standard_b64encode, standard_b64decode -import bson -from rosbridge_library.util import string_types +from rosbridge_library.util import string_types, bson import sys if sys.version_info >= (3, 0): diff --git a/rosbridge_library/src/rosbridge_library/protocol.py b/rosbridge_library/src/rosbridge_library/protocol.py index 9abe72ff9..013e57f20 100644 --- a/rosbridge_library/src/rosbridge_library/protocol.py +++ b/rosbridge_library/src/rosbridge_library/protocol.py @@ -32,13 +32,12 @@ import rospy import time -import bson from rosbridge_library.internal.exceptions import InvalidArgumentException from rosbridge_library.internal.exceptions import MissingArgumentException #from rosbridge_library.internal.pngcompression import encode from rosbridge_library.capabilities.fragmentation import Fragmentation -from rosbridge_library.util import json +from rosbridge_library.util import json, bson def is_number(s): diff --git a/rosbridge_library/src/rosbridge_library/util/__init__.py b/rosbridge_library/src/rosbridge_library/util/__init__.py index 885f8a515..f63dacf51 100644 --- a/rosbridge_library/src/rosbridge_library/util/__init__.py +++ b/rosbridge_library/src/rosbridge_library/util/__init__.py @@ -13,3 +13,13 @@ string_types = (str,) else: string_types = (str, unicode) + +import bson +try: + bson.BSON +except AttributeError: + raise Exception( + "BSON installation does not support all necessary features. " + "Please use the MongoDB BSON implementation. " + "See: https://github.com/RobotWebTools/rosbridge_suite/issues/198" + ) diff --git a/rosbridge_server/src/rosbridge_server/udp_handler.py b/rosbridge_server/src/rosbridge_server/udp_handler.py index 8ae691d5c..39a318bb3 100644 --- a/rosbridge_server/src/rosbridge_server/udp_handler.py +++ b/rosbridge_server/src/rosbridge_server/udp_handler.py @@ -1,7 +1,6 @@ import rospy from rosbridge_library.rosbridge_protocol import RosbridgeProtocol -from rosbridge_library.util import json -import bson +from rosbridge_library.util import json, bson from twisted.internet.protocol import DatagramProtocol,Factory diff --git a/rosbridge_server/src/rosbridge_server/websocket_handler.py b/rosbridge_server/src/rosbridge_server/websocket_handler.py index a058f6592..656cef36c 100755 --- a/rosbridge_server/src/rosbridge_server/websocket_handler.py +++ b/rosbridge_server/src/rosbridge_server/websocket_handler.py @@ -40,8 +40,7 @@ from tornado.websocket import WebSocketHandler from rosbridge_library.rosbridge_protocol import RosbridgeProtocol -from rosbridge_library.util import json -import bson +from rosbridge_library.util import json, bson class RosbridgeWebSocket(WebSocketHandler): client_id_seed = 0