Skip to content

Commit

Permalink
Fixes RobotWebTools#313 by fixing has_binary in protocol.py
Browse files Browse the repository at this point in the history
Checks for lists that have binary content as well as dicts
  • Loading branch information
Mohamed Behery committed Jan 16, 2018
1 parent 3d2e1ea commit 32ffa79
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions rosbridge_library/src/rosbridge_library/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,26 @@ def is_number(s):
return True
except ValueError:
return False

def has_binary(d):
if type(d)==bson.Binary:


def has_binary(obj):
""" Returns True if obj is a binary or contains a binary attribute
"""

if type(obj) is bson.binary.Binary:
return True
if type(d)==dict:
for k,v in d.items():

if type(obj) is list:
for item in obj:
if has_binary(item):
return True

if type(obj) is dict:
for k, v in obj.iteritems():
if has_binary(v):
return True
return False
return False


class Protocol:
""" The interface for a single client to interact with ROS.
Expand Down

0 comments on commit 32ffa79

Please sign in to comment.