Filters a context
    This will return a new context with only the resources that
    are actually available for use. Uses tags and command line
    options to make determination.
353
def filtered_context(context):
    """"""

    ctx = Context(context.opt)
    for resource in context.resources():
        if resource.child:
            continue

        if resource.filtered():
            ctx.add(resource)

    return ctx
813977
def placeholder_plugin_filter(self, request, queryset):
        
        if not request:
            return queryset
        if GLL.is_active:
            return queryset.filter(language=GLL.language_code)
        return queryset
363888
def _filter_sources(self, sources):
        
        filtered, hosts = [], []
        for source in sources:
            if 'error' in source:
                continue
            filtered.append(source)
            hosts.append(source['host_name'])

        return sorted(filtered, key=lambda s:
                      self._hosts_by_success(hosts).index(s['host_name']))
964672
def complete_contexts(self):
        '''
        
        '''
        if self._complete_contexts:
            return self._complete_contexts
        self.context()
        return self._complete_contexts
618321
def filter(self, model=None, context=None):
        
        if model is None:
            return

        # properties
        self.filter_properties(model, context=context)

        # entities
        self.filter_entities(model, context=context)

        # collections
        self.filter_collections(model, context=context)
1127257
def export_context(cls, context):
		
		if context is None:
			return
		result = [(x.context_name(), x.context_value()) for x in context]
		result.reverse()
		return tuple(result)
748561
def stanza_filter(filter_, func, order=_Undefined):
    
    if order is not _Undefined:
        return filter_.context_register(func, order)
    else:
        return filter_.context_register(func)
247794
def available(self, context):
	
		
		if self.__available is None:
			state = self.__inst.state(context)
			self.__available = state is not None and state != "not_created"
		return self.__available
131803
def for_context(context)
      contexts = hash.keys.select { |ckey| context.matches?([ckey]) }
      contexts.map { |exc| hash[exc] }
    end
420520
def filter_resource(self, resource_name, field_name, field_value,
                        result_handler=ONE_RESULT):
        
        return self.multi_filter_resource(resource_name,
                                          {field_name: field_value},
                                          result_handler=result_handler)
1325983
def filter_collections(self, model, context=None):
        
        if model is None:
            return

        for property_name in self.collections:
            prop = self.collections[property_name]
            collection = self.get(model, property_name)
            filtered_value = prop.filter(
                value=collection,
                model=model,
                context=context
            )
            self.set(model, property_name, filtered_value)

            prop.filter_with_schema(
                collection,
                context if prop.use_context else None
            )
187268
def get_context(awsclient, env, tool, command, arguments=None):
    
    # TODO: elapsed, artifact(stack, depl-grp, lambda, api)
    if arguments is None:
        arguments = {}
    context = {
        '_awsclient': awsclient,
        'env': env,
        'tool': tool,
        'command': command,
        '_arguments': arguments,  # TODO clean up arguments -> args
        'version': __version__,
        'user': _get_user(),
        'plugins': get_plugin_versions().keys()
    }

    return context
1364069
def _find_resources(resource, name=None, resource_id=None, tags=None,
                    region=None, key=None, keyid=None, profile=None):
    '''
    
    '''

    if all((resource_id, name)):
        raise SaltInvocationError('Only one of name or id may be '
                                  'provided.')

    if not any((resource_id, name, tags)):
        raise SaltInvocationError('At least one of the following must be '
                                  'provided: id, name, or tags.')

    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    f = 'get_all_{0}'.format(resource)
    if not f.endswith('s'):
        f = f + 's'
    get_resources = getattr(conn, f)

    filter_parameters = {}
    if name:
        filter_parameters['filters'] = {'tag:Name': name}
    if resource_id:
        filter_parameters['{0}_ids'.format(resource)] = resource_id
    if tags:
        for tag_name, tag_value in six.iteritems(tags):
            filter_parameters['filters']['tag:{0}'.format(tag_name)] = tag_value

    try:
        r = get_resources(**filter_parameters)
    except BotoServerError as e:
        if e.code.endswith('.NotFound'):
            return None
        raise
    return r
1104736
def filter(self, resource_manager, **params):
        """"""
        m = self.resolve(resource_manager.resource_type)
        client = resource_manager.get_client()

        enum_op, list_op, extra_args = m.enum_spec

        parent_type, annotate_parent = m.parent_spec
        parents = self.manager.get_resource_manager(parent_type)

        # Have to query separately for each parent's children.
        results = []
        for parent in parents.resources():
            if extra_args:
                params.update({key: parent[extra_args[key]] for key in extra_args.keys()})

            op = getattr(getattr(client, enum_op), list_op)
            subset = [r.serialize(True) for r in op(**params)]

            if annotate_parent:
                for r in subset:
                    r[self.parent_key] = parent[parents.resource_type.id]

            if subset:
                results.extend(subset)
        return results
1199696
def get_collection(self, request, **resources):
        
        if self._meta.queryset is None:
            return []

        # Filter collection
        filters = self.get_filters(request, **resources)
        filters.update(self.get_default_filters(**resources))
        qs = self._meta.queryset
        for key, (value, exclude) in filters.items():
            try:
                if exclude:
                    qs = qs.exclude(**{key: value})

                else:
                    qs = qs.filter(**{key: value})
            except FieldError, e:
                logger.warning(e)

        sorting = self.get_sorting(request, **resources)
        if sorting:
            qs = qs.order_by(*sorting)

        return qs
87059
def filter(self, value=None, model=None, context=None):
        
        if value is None:
            return value
        for filter_obj in self.filters:
            value = filter_obj.filter(
                value=value,
                model=model,
                context=context if self.use_context else None
            )
        return value
292280
protected function get_string_filters($context) {
        if (!isset($this->stringfilters[$context->id])) {
            $this->load_filters($context);
        }
        return $this->stringfilters[$context->id];
    }