code: def _coerce_topic(topic):
      
      if not isinstance(topic, string_types):
          raise TypeError('topic={!r} must be text'.format(topic))
      if not isinstance(topic, text_type):
          topic = topic.decode('ascii')
      if len(topic) < 1:
          raise ValueError('invalid empty topic name')
      if len(topic) > 249:
          raise ValueError('topic={!r} name is too long: {} > 249'.format(
              topic, len(topic)))
      return topic
docs: Ensure that the topic name is text string of a valid length.
  
      :param topic: Kafka topic name. Valid characters are in the set ``[a-zA-Z0-9._-]``.
      :raises ValueError: when the topic name exceeds 249 bytes
      :raises TypeError: when the topic is not :class:`unicode` or :class:`str`