'Returns the leader for a partition or None if the partition exists
but has no leader.
Raises:
UnknownTopicOrPartitionError: If the topic or partition is not part
of the metadata.
LeaderNotAvailableError: If the server has metadata, but there is no
current leader.'

def _get_leader_for_partition(self, topic, partition):

    key = TopicPartition(topic, partition)
    if (self.topics_to_brokers.get(key) is not None):
        return self.topics_to_brokers[key]
    self.load_metadata_for_topics(topic)
    if (partition not in self.topic_partitions.get(topic, [])):
        raise UnknownTopicOrPartitionError(key)
    leader = self.topic_partitions[topic][partition]
    if (leader == (-1)):
        raise LeaderNotAvailableError((topic, partition))
    return self.brokers[leader]
