diff options
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 |