diff options
author | Dana Powers <dana.powers@gmail.com> | 2014-08-22 16:35:22 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2014-08-22 16:35:22 -0700 |
commit | e2893360013a8800448290f176b5ce2da082f9c2 (patch) | |
tree | d72d2c54c9945ffc1bda13bf555e2d440f9aef7e /kafka/util.py | |
parent | c3df8a02150da4be7b45977b9145d6bf5bf8edf4 (diff) | |
parent | 6d6dc174cd1ecec6a74789562ce3d8a8f8e17261 (diff) | |
download | kafka-python-e2893360013a8800448290f176b5ce2da082f9c2.tar.gz |
Merge pull request #204 from mdaniel/better-type-errors
Better type errors
Diffstat (limited to 'kafka/util.py')
-rw-r--r-- | kafka/util.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/kafka/util.py b/kafka/util.py index a918234..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,9 +17,12 @@ 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): + elif len(s) > 32767 and sys.version < (2, 7): # Python 2.6 issues a deprecation warning instead of a struct error raise struct.error(len(s)) else: @@ -117,4 +123,5 @@ class ReentrantTimer(object): self.active.set() self.thread.join(self.t + 1) + # noinspection PyAttributeOutsideInit self.timer = None |