diff options
author | Mark Roberts <wizzat@gmail.com> | 2014-12-16 20:49:13 -0800 |
---|---|---|
committer | Mark Roberts <wizzat@gmail.com> | 2014-12-16 20:49:13 -0800 |
commit | 9c5216a97fde23c2619d3c4d72cab3f912949fbf (patch) | |
tree | d389018a668db9cb8a5e367edc745b4ddf1ae26d /kafka/util.py | |
parent | 30c87fb2d7049e27bb5d839791eb36dd790ad152 (diff) | |
parent | 29cae3e40b1d89d1a21525864794de7de3700461 (diff) | |
download | kafka-python-9c5216a97fde23c2619d3c4d72cab3f912949fbf.tar.gz |
Merge pull request #234 from dpkp/high_level_consumer
A simpler kafka consumer
Diffstat (limited to 'kafka/util.py')
-rw-r--r-- | kafka/util.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/kafka/util.py b/kafka/util.py index 1e03cf1..72ac521 100644 --- a/kafka/util.py +++ b/kafka/util.py @@ -86,6 +86,18 @@ def group_by_topic_and_partition(tuples): return out +def kafka_bytestring(s): + """ + Takes a string or bytes instance + Returns bytes, encoding strings in utf-8 as necessary + """ + if isinstance(s, six.binary_type): + return s + if isinstance(s, six.string_types): + return s.encode('utf-8') + raise TypeError(s) + + class ReentrantTimer(object): """ A timer that can be restarted, unlike threading.Timer |