diff options
author | Matthew L Daniel <mdaniel@gmail.com> | 2014-08-22 16:00:06 -0700 |
---|---|---|
committer | Matthew L Daniel <mdaniel@gmail.com> | 2014-08-22 16:01:02 -0700 |
commit | 6d6dc174cd1ecec6a74789562ce3d8a8f8e17261 (patch) | |
tree | dc0598bddcf987bf5ef7ffb395f2177d57b865d2 /kafka/util.py | |
parent | bb3827eb2e13820e52c138ce81f4076199e2ae4f (diff) | |
download | kafka-python-6d6dc174cd1ecec6a74789562ce3d8a8f8e17261.tar.gz |
Fix write_int and write_short type validation
It will still die, just as before, but it now includes a *helpful* error message
Diffstat (limited to 'kafka/util.py')
-rw-r--r-- | kafka/util.py | 6 |
1 files changed, 6 insertions, 0 deletions
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): |