summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMahendra M <mahendra.m@gmail.com>2013-10-08 14:46:02 +0530
committerMahendra M <mahendra.m@gmail.com>2013-10-08 14:46:02 +0530
commitceee715fc7bf17b28ff5a10f1f7decc8974f6506 (patch)
treeb4f36216f41b1843aa71b3354f3560b3721023a7
parent92d70e7310b5519a1be86f189a4ddb9d772a0434 (diff)
downloadkafka-python-ceee715fc7bf17b28ff5a10f1f7decc8974f6506.tar.gz
Add proper string representations for each class
-rw-r--r--kafka/client.py5
-rw-r--r--kafka/conn.py2
-rw-r--r--kafka/consumer.py8
-rw-r--r--kafka/producer.py6
4 files changed, 19 insertions, 2 deletions
diff --git a/kafka/client.py b/kafka/client.py
index 71ededa..51dda1e 100644
--- a/kafka/client.py
+++ b/kafka/client.py
@@ -174,7 +174,7 @@ class KafkaClient(object):
except ConnectionError, e: # ignore BufferUnderflow for now
log.warning("Could not send request [%s] to server %s: %s" % (request, conn, e))
failed_payloads += payloads
- self.topics_to_brokers = {} # reset metadata
+ self.topics_to_brokers = {} # reset metadata
continue
for response in decoder_fn(response):
@@ -186,6 +186,9 @@ class KafkaClient(object):
# Order the accumulated responses by the original key order
return (acc[k] for k in original_keys) if acc else ()
+ def __repr__(self):
+ return '<KafkaClient client_id=%s>' % (self.client_id)
+
#################
# Public API #
#################
diff --git a/kafka/conn.py b/kafka/conn.py
index 14aebc6..712b24d 100644
--- a/kafka/conn.py
+++ b/kafka/conn.py
@@ -29,7 +29,7 @@ class KafkaConnection(local):
self._sock.settimeout(10)
self._dirty = False
- def __str__(self):
+ def __repr__(self):
return "<KafkaConnection host=%s port=%d>" % (self.host, self.port)
###################
diff --git a/kafka/consumer.py b/kafka/consumer.py
index 7d44f28..ec04f5f 100644
--- a/kafka/consumer.py
+++ b/kafka/consumer.py
@@ -230,6 +230,10 @@ class SimpleConsumer(Consumer):
auto_commit_every_n=auto_commit_every_n,
auto_commit_every_t=auto_commit_every_t)
+ def __repr__(self):
+ return '<SimpleConsumer group=%s, topic=%s, partitions=%s>' % \
+ (self.group, self.topic, str(self.offsets.keys()))
+
def provide_partition_info(self):
"""
Indicates that partition info must be returned by the consumer
@@ -473,6 +477,10 @@ class MultiProcessConsumer(Consumer):
proc.start()
self.procs.append(proc)
+ def __repr__(self):
+ return '<MultiProcessConsumer group=%s, topic=%s, consumers=%d>' % \
+ (self.group, self.topic, len(self.procs))
+
def _consume(self, partitions):
"""
A child process worker which consumes messages based on the
diff --git a/kafka/producer.py b/kafka/producer.py
index 7ef7896..8275701 100644
--- a/kafka/producer.py
+++ b/kafka/producer.py
@@ -198,6 +198,9 @@ class SimpleProducer(Producer):
partition = self.next_partition.next()
return super(SimpleProducer, self).send_messages(partition, *msg)
+ def __repr__(self):
+ return '<SimpleProducer topic=%s, batch=%s>' % (self.topic, self.async)
+
class KeyedProducer(Producer):
"""
@@ -239,3 +242,6 @@ class KeyedProducer(Producer):
partitions = self.client.topic_partitions[self.topic]
partition = self.partitioner.partition(key, partitions)
return self.send_messages(partition, msg)
+
+ def __repr__(self):
+ return '<KeyedProducer topic=%s, batch=%s>' % (self.topic, self.async)