Given a topic, checks whether the user can add it to their subscription list.
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')
        )
958902
def register_subscriber(topic, topic_type)
      code, message,val = @proxy.registerSubscriber(@caller_id,
                                                    topic,
                                                    topic_type,
                                                    @slave_uri)
      if code == 1
        val
      elsif code == 0
        puts message
        val
      else
        raise message
      end
    end
1004685
public function canPublish($member = null)
    {
        if (!$member) {
            $member = Security::getCurrentUser();
        }
        // Check all explicitly added items
        foreach ($this->Changes()->filter(['Added' => ChangeSetItem::EXPLICITLY]) as $change) {
            /** @var ChangeSetItem $change */
            if (!$change->canPublish($member)) {
                return false;
            }
        }

        return true;
    }
632013
function subscribe() {
  console.log('Subscribing client ' + clientId + ' to topic: ' + topics.subscribe);
  client.subscribe(topics.subscribe);
  isSubscribed = true;
}
1197222
def mpub(self, topic, *messages):
        ''''''
        return self.send(constants.MPUB + ' ' + topic, messages)
293951
@Override
	public TopicSubscriber createSubscriber(Topic topic) throws JMSException
    {
        return createSubscriber(topic,null,false);
    }
419568
def subscribe(self, topic, callback, qos):
        """"""
        if topic in self.topics:
            return

        def _message_callback(mqttc, userdata, msg):
            """Callback added to callback list for received message."""
            callback(msg.topic, msg.payload.decode('utf-8'), msg.qos)

        self._mqttc.subscribe(topic, qos)
        self._mqttc.message_callback_add(topic, _message_callback)
        self.topics[topic] = callback
815777
def add_subscriber(subscriber)
      uris = @master.register_subscriber(subscriber.topic_name,
                                         subscriber.topic_type.type)
      subscriber.set_manager(self)
      uris.each do |publisher_uri|
        subscriber.add_connection(publisher_uri)
      end
      @subscribers.push(subscriber)
      subscriber
    end
198085
@VisibleForTesting
  synchronized void consumerSubscriptionRebalance() {
    log.debug("Subscribed Topics " + this.consumer.subscription());
    if (!this.subscribedTopics.isEmpty()) {
      final Iterator<String> iter = this.subscribedTopics.iterator();
      final List<String> topics = new ArrayList<>();
      while (iter.hasNext()) {
        topics.add(iter.next());
      }
      this.subscribedTopics.clear();
      //re-subscribe topics that are needed
      this.consumer.subscribe(topics);
    }
  }
934296
protected void sendSubscribe(String topic) {
    assert topic != null : "topic shouldn't be null";
    JsonObject msg = Json.createObject().set(TYPE, "register").set(TOPIC, topic);
    send(msg);
  }
163394
def add(self, list_id, email_address, name, custom_fields, resubscribe, consent_to_track, restart_subscription_based_autoresponders=False):
        """"""
        validate_consent_to_track(consent_to_track)
        body = {
            "EmailAddress": email_address,
            "Name": name,
            "CustomFields": custom_fields,
            "Resubscribe": resubscribe,
            "ConsentToTrack": consent_to_track,
            "RestartSubscriptionBasedAutoresponders": restart_subscription_based_autoresponders}
        response = self._post("/subscribers/%s.json" %
                              list_id, json.dumps(body))
        return json_to_py(response)
454405
def verify_sns_subscription_current(self, subscription_arn, topic_name,
                                        function_arn):
        # type: (str, str, str) -> bool
        
        sns_client = self._client('sns')
        try:
            attributes = sns_client.get_subscription_attributes(
                SubscriptionArn=subscription_arn)['Attributes']
            return (
                # Splitting on ':' is safe because topic names can't have
                # a ':' char.
                attributes['TopicArn'].rsplit(':', 1)[1] == topic_name and
                attributes['Endpoint'] == function_arn
            )
        except sns_client.exceptions.NotFoundException:
            return False
509426
def can_unsubscribe_from_topic(self, topic, user):
        
        # A user can unsubscribe from topics if they are authenticated and if they have the
        # permission to read the related forum. Of course a user can unsubscribe only if they are
        #  already a subscriber of the considered topic.
        return (
            user.is_authenticated and
            topic.has_subscriber(user) and
            self._perform_basic_permission_check(topic.forum, user, 'can_read_forum')
        )
538735
def checked_emit(self, value: Any) -> asyncio.Future:
        

        if not isinstance(self._subject, Subscriber):
            raise TypeError('Topic %r has to be a subscriber' % self._path)

        value = self.cast(value)
        self.check(value)
        return self._subject.emit(value, who=self)
976527
def has_subscriber(self, user):
        
        if not hasattr(self, '_subscribers'):
            self._subscribers = list(self.subscribers.all())
        return user in self._subscribers
1067800
def subscribe(self, topic, channel):
        """"""
        self.send(nsq.subscribe(topic, channel))
1309234
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_subscribe_to_topic(obj, user)