Verify the pub/sub topic exists.

        Returns the topic qualified name.
503390
def ensure_topic(self):
        
        client = self.session.client('pubsub', 'v1', 'projects.topics')
        topic = self.get_topic_param()
        try:
            client.execute_command('get', {'topic': topic})
        except HttpError as e:
            if e.resp.status != 404:
                raise
        else:
            return topic

        # bug in discovery doc.. apis say body must be empty but its required in the
        # discovery api for create.
        client.execute_command('create', {'name': topic, 'body': {}})
        return topic
548727
def get_pub_id_owner(self, pub_id):
        """"""
        con = self.connection or self._connect()
        cur = con.cursor()

        cur.execute(
            """SELECT distinct username from upload.reaction
            WHERE pub_id = '{pub_id}'"""
            .format(pub_id=pub_id))

        username = cur.fetchall()[0][0]

        return username
1129390
public boolean topicExists(String topicName) {
        Map<String, List<PartitionInfo>> topicInfo = getTopicInfo();
        return topicInfo != null && topicInfo.containsKey(topicName);
    }
1292346
def validate_sns_topic_subscription(self, region):
        
        sns = self.session.client('sns', region_name=region)
        arn = 'arn:aws:sns:{}:{}:{}'.format(region, self.account.account_number, self.topic_name)
        try:
            data = sns.list_subscriptions_by_topic(TopicArn=arn)
        except ClientError as ex:
            self.log.error('Failed to list subscriptions by topic in {} ({}): {}'.format(
                self.account.account_name,
                region,
                ex
            ))
            return False

        for sub in data['Subscriptions']:
            if sub['Endpoint'] == self.sqs_queue:
                if sub['SubscriptionArn'] == 'PendingConfirmation':
                    self.log.warning('Subscription pending confirmation for {} in {}'.format(
                        self.account.account_name,
                        region
                    ))
                    return False
                return True

        return False
486320
private MemberId getNextMemberId(String topicName) {
    InternalTopic topic = topics.get(topicName);
    if (topic == null) {
      return null;
    }

    TopicIterator iterator = topic.iterator();
    if (iterator.hasNext()) {
      return iterator.next().memberId();
    }
    return null;
  }
28721
function verifyProjectNameDoesNotExist(req, res, next) {
  var projectName = req.body.name.toLowerCase();
  var dataStore = req.app.dataStore;

  // Get all project REST resources
  dataStore.getCollection('/projects', function(err, resources) {
    var alreadyExists = resources.some(function(resource) {
      return resource.data.name.toLowerCase() === projectName;
    });

    if (alreadyExists) {
      // The ID already exists, so send an HTTP 409 (Conflict)
      res.sendStatus(409);
    }
    else {
      next();
    }
  });
}
1082661
def find_topic(category_name, forum_name, topic_title, options = {})
      forum = self.find_forum(category_name, forum_name, options)
      if forum
        self.topics(forum['id'], options).detect {|t| t['title'] == topic_title}
      end
    end
588755
def create_topic(self, topic_name, topic_config):
        
        topic_subs = []
        t = self.template

        if "Subscription" in topic_config:
            topic_subs = topic_config["Subscription"]

        t.add_resource(
            sns.Topic.from_dict(
                topic_name,
                topic_config
            )
        )

        topic_arn = Ref(topic_name)

        t.add_output(
            Output(topic_name + "Name", Value=GetAtt(topic_name, "TopicName"))
        )
        t.add_output(Output(topic_name + "Arn", Value=topic_arn))

        sqs_subs = [sub for sub in topic_subs if sub["Protocol"] == "sqs"]
        if sqs_subs:
            self.create_sqs_policy(topic_name, topic_arn, sqs_subs)
1328403
def pub(topic_name, json_msg, repeat_rate=None, host=jps.env.get_master_host(), pub_port=jps.DEFAULT_PUB_PORT):
    '''
    '''
    pub = jps.Publisher(topic_name, host=host, pub_port=pub_port)
    time.sleep(0.1)
    if repeat_rate is None:
        pub.publish(json_msg)
    else:
        try:
            while True:
                pub.publish(json_msg)
                time.sleep(1.0 / repeat_rate)
        except KeyboardInterrupt:
            pass
254709
static public function CheckTopicName($topic_name)
    {
        if (!isset($topic_name[0]) || isset($topic_name[65535])) {
            throw new Exception('Topic name must be at 1~65535 bytes long');
        }

        self::ValidateUTF8($topic_name);

        if (false !== strpos($topic_name, chr(0))) {
            throw new Exception('null character is not allowed in topic');
        }
        if (false !== strpos($topic_name, '#')) {
            throw new Exception('# is not allowed in topic');
        }
        if (false !== strpos($topic_name, '+')) {
            throw new Exception('+ is not allowed in topic');
        }
    }
21274
def community_topic_subscription_show(self, topic_id, id, **kwargs):
        ""
        api_path = "/api/v2/community/topics/{topic_id}/subscriptions/{id}.json"
        api_path = api_path.format(topic_id=topic_id, id=id)
        return self.call(api_path, **kwargs)
906698
private boolean verifyHostname(String hostname, X509Certificate certificate) {
        hostname = hostname.toLowerCase(Locale.US);
        boolean hasDns = false;
        List<String> altNames = getSubjectAltNames(certificate, ALT_DNS_NAME);
        for (int i = 0, size = altNames.size(); i < size; i++) {
            hasDns = true;
            if (verifyHostname(hostname, altNames.get(i))) {
                return true;
            }
        }

        if (!hasDns) {
            X500Principal principal = certificate.getSubjectX500Principal();
            // RFC 2818 advises using the most specific name for matching.
            String cn = new DistinguishedNameParser(principal).findMostSpecific("cn");
            if (cn != null) {
                return verifyHostname(hostname, cn);
            }
            else {
                // NOTE: In case of empty Common Name (CN), not checking
                return true;
            }
        }

        return false;
    }
189537
public Topic getTopic(String topicName) throws ServiceLocatorException {
		Topic topic = null;
		try {
			topic = (Topic) ic.lookup(topicName);
		} catch (NamingException ne) {
			throw new ServiceLocatorException(ne);
		} catch (Exception e) {
			throw new ServiceLocatorException(e);
		}
		return topic;
	}
982608
def is_topic_head(self):
        
        return self.topic.first_post.id == self.id if self.topic.first_post else False
316496
def _ensure_valid_topic_name(self, topic):
        

        # See Kafka Source:
        # https://github.com/apache/kafka/blob/39eb31feaeebfb184d98cc5d94da9148c2319d81/clients/src/main/java/org/apache/kafka/common/internals/Topic.java
        if topic is None:
            raise TypeError('All topics must not be None')
        if not isinstance(topic, six.string_types):
            raise TypeError('All topics must be strings')
        if len(topic) == 0:
            raise ValueError('All topics must be non-empty strings')
        if topic == '.' or topic == '..':
            raise ValueError('Topic name cannot be "." or ".."')
        if len(topic) > self._MAX_NAME_LENGTH:
            raise ValueError('Topic name is illegal, it can\'t be longer than {0} characters, topic: "{1}"'.format(self._MAX_NAME_LENGTH, topic))
        if not self._TOPIC_LEGAL_CHARS.match(topic):
            raise ValueError('Topic name "{0}" is illegal, it contains a character other than ASCII alphanumerics, ".", "_" and "-"'.format(topic))
559249
def can_subscribe_to_topic(self, topic, user):
        
        # A user can subscribe to topics if they are authenticated and if they have the permission
        # to read the related forum. Of course a user can subscribe only if they have not already
        # subscribed to the considered topic.
        return (
            user.is_authenticated and
            not topic.has_subscriber(user) and
            self._perform_basic_permission_check(topic.forum, user, 'can_read_forum')
        )
1199229
public boolean isMatchingTopic(String topic) {
		if (isFixedTopics()) {
			return getFixedTopics().contains(topic);
		} else {
			return topicPattern.matcher(topic).matches();
		}
	}