11"""
22Kafka Admin client: create, view, alter, delete topics and resources.
33"""
4- from ..cimpl import (KafkaException , # noqa
5- _AdminClientImpl ,
6- NewTopic ,
7- NewPartitions ,
8- CONFIG_SOURCE_UNKNOWN_CONFIG ,
9- CONFIG_SOURCE_DYNAMIC_TOPIC_CONFIG ,
10- CONFIG_SOURCE_DYNAMIC_BROKER_CONFIG ,
11- CONFIG_SOURCE_DYNAMIC_DEFAULT_BROKER_CONFIG ,
12- CONFIG_SOURCE_STATIC_BROKER_CONFIG ,
13- CONFIG_SOURCE_DEFAULT_CONFIG ,
14- RESOURCE_UNKNOWN ,
15- RESOURCE_ANY ,
16- RESOURCE_TOPIC ,
17- RESOURCE_GROUP ,
18- RESOURCE_BROKER )
4+ from confluent_kafka .cimpl import (KafkaException ,
5+ _AdminClientImpl ,
6+ NewTopic ,
7+ NewPartitions ,
8+ CONFIG_SOURCE_UNKNOWN_CONFIG ,
9+ CONFIG_SOURCE_DYNAMIC_TOPIC_CONFIG ,
10+ CONFIG_SOURCE_DYNAMIC_BROKER_CONFIG ,
11+ CONFIG_SOURCE_DYNAMIC_DEFAULT_BROKER_CONFIG ,
12+ CONFIG_SOURCE_STATIC_BROKER_CONFIG ,
13+ CONFIG_SOURCE_DEFAULT_CONFIG ,
14+ RESOURCE_UNKNOWN ,
15+ RESOURCE_ANY ,
16+ RESOURCE_TOPIC ,
17+ RESOURCE_GROUP ,
18+ RESOURCE_BROKER )
19+
20+ __all__ = ['CONFIG_SOURCE_DEFAULT_CONFIG' ,
21+ 'CONFIG_SOURCE_DYNAMIC_BROKER_CONFIG' ,
22+ 'CONFIG_SOURCE_DYNAMIC_DEFAULT_BROKER_CONFIG' ,
23+ 'CONFIG_SOURCE_DYNAMIC_TOPIC_CONFIG' ,
24+ 'CONFIG_SOURCE_STATIC_BROKER_CONFIG' ,
25+ 'CONFIG_SOURCE_UNKNOWN_CONFIG' ,
26+ 'NewTopic' ,
27+ 'NewPartitions' ]
1928
2029import concurrent .futures
2130import functools
@@ -122,7 +131,8 @@ def __init__(self, restype, name,
122131 try :
123132 restype = ConfigResource .Type [restype .upper ()]
124133 except KeyError :
125- raise ValueError ("Unknown resource type \" %s\" : should be a ConfigResource.Type" % restype )
134+ raise ValueError (
135+ "Unknown resource type \" %s\" : should be a ConfigResource.Type" % restype )
126136
127137 elif type (restype ) == int :
128138 # The C-code passes restype as an int, convert to Type.
@@ -182,7 +192,7 @@ def set_config(self, name, value, overwrite=True):
182192 self .set_config_dict [name ] = value
183193
184194
185- class AdminClient (_AdminClientImpl ):
195+ class AdminClient (_AdminClientImpl ):
186196 """
187197 AdminClient provides admin operations for Kafka brokers, topics, groups,
188198 and other resource types supported by the broker.
@@ -203,6 +213,7 @@ class AdminClient (_AdminClientImpl):
203213
204214 Requires broker version v0.11.0.0 or later.
205215 """
216+
206217 def __init__ (self , conf ):
207218 """
208219 Create a new AdminClient using the provided configuration dictionary.
@@ -250,7 +261,8 @@ def _make_resource_result(f, futmap):
250261 for resource , configs in result .items ():
251262 fut = futmap .get (resource , None )
252263 if fut is None :
253- raise RuntimeError ("Resource {} not found in future-map: {}" .format (resource , futmap ))
264+ raise RuntimeError (
265+ "Resource {} not found in future-map: {}" .format (resource , futmap ))
254266 if resource .error is not None :
255267 # Resource-level exception
256268 fut .set_exception (KafkaException (resource .error ))
@@ -462,7 +474,7 @@ def alter_configs(self, resources, **kwargs):
462474 return futmap
463475
464476
465- class ClusterMetadata (object ):
477+ class ClusterMetadata (object ):
466478 """
467479 ClusterMetadata as returned by list_topics() contains information
468480 about the Kafka cluster, brokers, and topics.
@@ -476,6 +488,7 @@ class ClusterMetadata (object):
476488 :ivar int orig_broker_id: The broker this metadata originated from.
477489 :ivar str orig_broker_name: Broker name/address this metadata originated from.
478490 """
491+
479492 def __init__ (self ):
480493 self .cluster_id = None
481494 self .controller_id = - 1
@@ -491,7 +504,7 @@ def __str__(self):
491504 return str (self .cluster_id )
492505
493506
494- class BrokerMetadata (object ):
507+ class BrokerMetadata (object ):
495508 """
496509 BrokerMetadata contains information about a Kafka broker.
497510
@@ -501,6 +514,7 @@ class BrokerMetadata (object):
501514 :ivar str host: Broker hostname.
502515 :ivar int port: Broker port.
503516 """
517+
504518 def __init__ (self ):
505519 self .id = - 1
506520 self .host = None
@@ -513,7 +527,7 @@ def __str__(self):
513527 return "{}:{}/{}" .format (self .host , self .port , self .id )
514528
515529
516- class TopicMetadata (object ):
530+ class TopicMetadata (object ):
517531 """
518532 TopicMetadata contains information about a Kafka topic.
519533
@@ -523,6 +537,7 @@ class TopicMetadata (object):
523537 :ivar dict partitions: Map of partitions indexed by partition id. Value is PartitionMetadata object.
524538 :ivar KafkaError -error: Topic error, or None. Value is a KafkaError object.
525539 """
540+
526541 # The dash in "-topic" and "-error" is needed to circumvent a
527542 # Sphinx issue where it tries to reference the same instance variable
528543 # on other classes which raises a warning/error.
@@ -533,15 +548,16 @@ def __init__(self):
533548
534549 def __repr__ (self ):
535550 if self .error is not None :
536- return "TopicMetadata({}, {} partitions, {})" .format (self .topic , len (self .partitions ), self .error )
551+ return "TopicMetadata({}, {} partitions, {})" .format (self .topic , len (self .partitions ),
552+ self .error )
537553 else :
538554 return "TopicMetadata({}, {} partitions)" .format (self .topic , len (self .partitions ))
539555
540556 def __str__ (self ):
541557 return self .topic
542558
543559
544- class PartitionMetadata (object ):
560+ class PartitionMetadata (object ):
545561 """
546562 PartitionsMetadata contains information about a Kafka partition.
547563
@@ -558,6 +574,7 @@ class PartitionMetadata (object):
558574 in ClusterMetadata.brokers. Always check the availability
559575 of a broker id in the brokers dict.
560576 """
577+
561578 def __init__ (self ):
562579 self .id = - 1
563580 self .leader = - 1
0 commit comments