Add proper string representations for each class
This commit is contained in:
@@ -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 #
|
||||
#################
|
||||
|
||||
@@ -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)
|
||||
|
||||
###################
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user