summaryrefslogtreecommitdiff
path: root/kafka/util.py
diff options
context:
space:
mode:
authorDana Powers <dana.powers@rd.io>2014-12-11 16:35:15 -0800
committerDana Powers <dana.powers@rd.io>2014-12-15 12:43:45 -0800
commited893c3bcfdf54f440b98b958c86fc0c13573b6f (patch)
tree10bf13e8b3efa1ffae30f057dadf4e8655a2063a /kafka/util.py
parent209a8f28e6df2c5be8117b3bbb1b3188f1e29adc (diff)
downloadkafka-python-ed893c3bcfdf54f440b98b958c86fc0c13573b6f.tar.gz
Use kafka.util.kafka_bytestring to encode utf-8 when necessary
Diffstat (limited to 'kafka/util.py')
-rw-r--r--kafka/util.py12
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