Only apply tags and default for top-level key, effectively scoping the tags.
353917
def scope(self, key, *tags, default=None):
        """"""
        scope = self._scopes[key]
        tags = self._ensure_exclamation(tags)
        default = default if not default or default.startswith("!") else "!" + default

        if scope:
            scope[0] = scope[0] + tags
            scope[1] = default if default else scope[1]
        else:
            scope.append(tags)
            scope.append(default)
446267
def set_tag(self, key, value):
        
        with self.update_lock:
            if key == ext_tags.SAMPLING_PRIORITY and not self._set_sampling_priority(value):
                return self
            if self.is_sampled():
                tag = thrift.make_tag(
                    key=key,
                    value=value,
                    max_length=self.tracer.max_tag_value_length, )
                self.tags.append(tag)
        return self
458301
@JsonIgnore
    public void setTag(String key, String value) {
        requireArgument(key != null && !key.trim().isEmpty(), "Tag key cannot be null.");
        requireArgument(!ReservedField.isReservedField(key), "Tag is a reserved tag name.");
        if (value == null || value.isEmpty()) {
            _tags.remove(key);
        } else {
            _tags.put(key, value);
        }
    }
316007
def get(key, default=-1):
        """"""
        if isinstance(key, int):
            return TaggerId(key)
        if key not in TaggerId._member_map_:
            extend_enum(TaggerId, key, default)
        return TaggerId[key]
548121
static boolean applyTags(RuleDto rule, Set<String> tags) {
    for (String tag : tags) {
      RuleTagFormat.validate(tag);
    }

    Set<String> initialTags = rule.getTags();
    final Set<String> systemTags = rule.getSystemTags();
    Set<String> withoutSystemTags = Sets.filter(tags, input -> input != null && !systemTags.contains(input));
    rule.setTags(withoutSystemTags);
    return withoutSystemTags.size() != initialTags.size() || !withoutSystemTags.containsAll(initialTags);
  }
303884
def set_to_default(section, key):
    
    section[key] = section.default_values.get(key, section[key])
1174920
def filter_metadata(metadata, user_filter, default_filter):
    """"""
    actual_keys = set(metadata.keys())
    keep_keys = apply_metadata_filters(user_filter, default_filter, actual_keys)

    for key in actual_keys:
        if key not in keep_keys:
            metadata.pop(key)

    return metadata
626844
def pull_tag_dict(data):
    
    # If there are tags, set them to a normal dict, vs. a list of dicts:
    tags = data.pop('Tags', {}) or {}
    if tags:
        proper_tags = {}
        for tag in tags:
            proper_tags[tag['Key']] = tag['Value']

        tags = proper_tags

    return tags
730590
def tag_stuff(self):
        """"""

        # For each packet in the pcap process the contents
        for item in self.input_stream:

            # Make sure it has a tags field (which is a set)
            if 'tags' not in item:
                item['tags'] = set()

            # For each tag_methods run it on the item
            for tag_method in self.tag_methods:
                item['tags'].add(tag_method(item))

            # Not interested in None tags
            if None in item['tags']:
                item['tags'].remove(None)
            # All done
            yield item
198187
def filter_input(keys, raw):
    """"""
    if len(keys) == 1:
        if keys[0] in UI.keys['up']:
            keys[0] = 'up'
        elif keys[0] in UI.keys['down']:
            keys[0] = 'down'
        elif len(keys[0]) == 4 and keys[0][0] == 'mouse press':
            if keys[0][1] == 4:
                keys[0] = 'up'
            elif keys[0][1] == 5:
                keys[0] = 'down'
    return keys
216821
public static Tags of(String key, String value) {
        return new Tags(new Tag[]{Tag.of(key, value)});
    }
591397
static void putIfNotSet(Map<String, String> target, Map<String, String> defaults) {
    for (final String key : defaults.keySet()) {
      if (!target.containsKey(key)) {
        target.put(key, defaults.get(key));
      }
    }
  }
402287
def sanitized_tags
      @tags.select do |key, value|
        ALLOWED_TAG_KEY_TYPES.any? { |type| key.is_a? type } &&
          ALLOWED_TAG_VALUE_TYPES.any? { |type| value.is_a? type }
      end
    end
1066666
public void setTagKeys(java.util.Collection<String> tagKeys) {
        if (tagKeys == null) {
            this.tagKeys = null;
            return;
        }

        this.tagKeys = new java.util.ArrayList<String>(tagKeys);
    }
175715
def set_tags(self, value):
        """"""
        if self.action == "remove":
            log = (
                "Tag-based filtering can only be used when adding "
                "participant probes for a measurement."
            )
            raise MalFormattedSource(log)
        super(AtlasChangeSource, self).set_tags(value)
429509
public static Tag newTag(String key, String value) {
    Tag newTag = new BasicTag(intern(key), intern(value));
    return intern(newTag);
  }
1356217
def cache_invalidate_by_tags(tags, cache=None):
    
    if isinstance(tags, basestring):
        tags = [tags]
    tag_keys = [CACHE_TAG_KEY % tag for tag in tags if tag]
    if not tag_keys:
        raise ValueError('Attr tags invalid')
    if cache is None:
        cache = default_cache
    tag_keys_for_delete = []
    if cache.__class__.__name__ == 'RedisCache':
        from django_redis.exceptions import ConnectionInterrupted
        try:
            redis_client = cache.client.get_client()
            for tag_key in tag_keys:
                keys = redis_client.smembers(tag_key)
                if keys:
                    cache.delete_many(keys)
                    tag_keys_for_delete.append(tag_key)
        except ConnectionInterrupted:
            pass  # todo add logging
    else:
        for tag_key in tag_keys:
            keys = cache.get(tag_key)
            if keys:
                cache.delete_many(keys)
                tag_keys_for_delete.append(tag_key)
    if tag_keys_for_delete:
        cache.delete_many(tag_keys_for_delete)