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 of binary objects inside the objects as well as dictionaries
  • Loading branch information
Mohamed Behery committed Jan 9, 2018
1 parent a26ce77 commit ad28578
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions rosbridge_library/src/rosbridge_library/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ def is_number(s):
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 ad28578

Please sign in to comment.