From 6d6dc174cd1ecec6a74789562ce3d8a8f8e17261 Mon Sep 17 00:00:00 2001 From: Matthew L Daniel Date: Fri, 22 Aug 2014 16:00:06 -0700 Subject: Fix write_int and write_short type validation It will still die, just as before, but it now includes a *helpful* error message --- kafka/util.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'kafka/util.py') diff --git a/kafka/util.py b/kafka/util.py index 09a5bbb..9121374 100644 --- a/kafka/util.py +++ b/kafka/util.py @@ -7,6 +7,9 @@ from kafka.common import BufferUnderflowError def write_int_string(s): + if s is not None and not isinstance(s, str): + raise TypeError('Expected "%s" to be str\n' + 'data=%s' % (type(s), repr(s))) if s is None: return struct.pack('>i', -1) else: @@ -14,6 +17,9 @@ def write_int_string(s): def write_short_string(s): + if s is not None and not isinstance(s, str): + raise TypeError('Expected "%s" to be str\n' + 'data=%s' % (type(s), repr(s))) if s is None: return struct.pack('>h', -1) elif len(s) > 32767 and sys.version < (2, 7): -- cgit v1.2.1