From 698c3dc7e689cf07b623506053f290ee9ed593a6 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 14 Oct 2015 23:40:40 +0200 Subject: [PATCH 1/2] When empty array or dictionary were passed for data, an uncatched TypeError exception was raised. --- socketio/packet.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/socketio/packet.py b/socketio/packet.py index 642e179e..f349aae4 100644 --- a/socketio/packet.py +++ b/socketio/packet.py @@ -135,17 +135,25 @@ def _deconstruct_binary_internal(self, data, attachments): 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 From d8782dc59415abfde2e03da27bdc80279315846c Mon Sep 17 00:00:00 2001 From: david Date: Wed, 14 Oct 2015 23:44:23 +0200 Subject: [PATCH 2/2] formatting --- socketio/packet.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/socketio/packet.py b/socketio/packet.py index f349aae4..7a3c9417 100644 --- a/socketio/packet.py +++ b/socketio/packet.py @@ -135,11 +135,6 @@ def _deconstruct_binary_internal(self, data, attachments): else: return data - - - - - def _data_is_binary(self, data): """Check if the data contains binary components.""" try: