summaryrefslogtreecommitdiff
path: root/kafka/util.py
diff options
context:
space:
mode:
authorDana Powers <dana.powers@rd.io>2016-01-07 18:51:14 -0800
committerDana Powers <dana.powers@rd.io>2016-01-07 18:51:14 -0800
commit828377377da43749af0d27ee256ef31bf714cf17 (patch)
treefbad4d4381fc4d1ea2be7ce2009214d18fbeb674 /kafka/util.py
parent71e7568fcb8132899f366b37c32645fd5a40dc4b (diff)
parent9a8af1499ca425366d934487469d9977fae7fe5f (diff)
downloadkafka-python-828377377da43749af0d27ee256ef31bf714cf17.tar.gz
Merge branch '0.9'
Conflicts: kafka/codec.py kafka/version.py test/test_producer.py test/test_producer_integration.py
Diffstat (limited to 'kafka/util.py')
-rw-r--r--kafka/util.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/kafka/util.py b/kafka/util.py
index 6d9d307..c6e77fa 100644
--- a/kafka/util.py
+++ b/kafka/util.py
@@ -10,7 +10,13 @@ from kafka.common import BufferUnderflowError
def crc32(data):
- return binascii.crc32(data) & 0xffffffff
+ crc = binascii.crc32(data)
+ # py2 and py3 behave a little differently
+ # CRC is encoded as a signed int in kafka protocol
+ # so we'll convert the py3 unsigned result to signed
+ if six.PY3 and crc >= 2**31:
+ crc -= 2**32
+ return crc
def write_int_string(s):
@@ -89,18 +95,6 @@ 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