Browse Source

When empty array or dictionary were passed for data, an uncatched TypeError exception was raised.

pull/5/head
david 10 years ago
parent
commit
698c3dc7e6
  1. 30
      socketio/packet.py

30
socketio/packet.py

@ -135,17 +135,25 @@ class Packet(object):
else:
return data
def _data_is_binary(self, data):
"""Check if the data contains binary components."""
if isinstance(data, six.binary_type):
return True
elif isinstance(data, list):
return functools.reduce(
lambda a, b: a or b, [self._data_is_binary(item)
for item in data])
elif isinstance(data, dict):
return functools.reduce(
lambda a, b: a or b, [self._data_is_binary(item)
for item in six.itervalues(data)])
else:
try:
if isinstance(data, six.binary_type):
return True
elif isinstance(data, list):
return functools.reduce(
lambda a, b: a or b, [self._data_is_binary(item)
for item in data])
elif isinstance(data, dict):
return functools.reduce(
lambda a, b: a or b, [self._data_is_binary(item)
for item in six.itervalues(data)])
else:
return False
except TypeError:
return False

Loading…
Cancel
Save