def _get_leader_for_partition(self, topic, partition):
key = TopicAndPartition(topic, partition)<EOL>if self.topics_to_brokers.get(key) is not None:<EOL><INDENT>return self.topics_to_brokers[key]<EOL><DEDENT>self.load_metadata_for_topics(topic)<EOL>if partition not in self.topic_partitions.get(topic, []):<EOL><INDENT>raise UnknownTopicOrPartitionError(key)<EOL><DEDENT>meta = self.topic_partitions[topic][partition]<EOL>if meta.leader == -<NUM_LIT:1>:<EOL><INDENT>raise LeaderNotAvailableError(meta)<EOL><DEDENT>return self.brokers[meta.leader]<EOL>
Returns the leader for a partition or None if the partition exists
but has no leader.

UnknownTopicOrPartitionError will be raised if the topic or partition
is not part of the metadata.

LeaderNotAvailableError is raised if server has metadata, but there is
no current leader