diff options
author | Dana Powers <dana.powers@rd.io> | 2014-09-07 18:52:05 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@rd.io> | 2014-09-07 19:09:32 -0700 |
commit | 715425c639a476139065689afde3d255a07d6f96 (patch) | |
tree | 0ef2cd875c97c8ca867d89328d6fd5fec7dfcbe8 /kafka/conn.py | |
parent | a99384f4c601d127ab1c4fe5b272ea5c07fd695d (diff) | |
parent | be23042ecd9ab330886745ccc9ec9e3a0039836f (diff) | |
download | kafka-python-715425c639a476139065689afde3d255a07d6f96.tar.gz |
Merge pull request #227 from wizzat-feature/py3
Python 3 Support
Conflicts:
kafka/producer.py
test/test_client.py
test/test_client_integration.py
test/test_codec.py
test/test_consumer.py
test/test_consumer_integration.py
test/test_failover_integration.py
test/test_producer.py
test/test_producer_integration.py
test/test_protocol.py
test/test_util.py
Diffstat (limited to 'kafka/conn.py')
-rw-r--r-- | kafka/conn.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/kafka/conn.py b/kafka/conn.py index a577eba..ddfee8b 100644 --- a/kafka/conn.py +++ b/kafka/conn.py @@ -5,6 +5,8 @@ import socket import struct from threading import local +import six + from kafka.common import ConnectionError log = logging.getLogger("kafka") @@ -19,7 +21,7 @@ def collect_hosts(hosts, randomize=True): randomize the returned list. """ - if isinstance(hosts, basestring): + if isinstance(hosts, six.string_types): hosts = hosts.strip().split(',') result = [] @@ -92,7 +94,7 @@ class KafkaConnection(local): # Receiving empty string from recv signals # that the socket is in error. we will never get # more data from this socket - if data == '': + if data == b'': raise socket.error("Not enough data to read message -- did server kill socket?") except socket.error: @@ -103,7 +105,7 @@ class KafkaConnection(local): log.debug("Read %d/%d bytes from Kafka", num_bytes - bytes_left, num_bytes) responses.append(data) - return ''.join(responses) + return b''.join(responses) ################## # Public API # @@ -144,7 +146,7 @@ class KafkaConnection(local): # Read the remainder of the response resp = self._read_bytes(size) - return str(resp) + return resp def copy(self): """ @@ -153,6 +155,10 @@ class KafkaConnection(local): return a new KafkaConnection object """ c = copy.deepcopy(self) + # Python 3 doesn't copy custom attributes of the threadlocal subclass + c.host = copy.copy(self.host) + c.port = copy.copy(self.port) + c.timeout = copy.copy(self.timeout) c._sock = None return c |