'Register a callable as a template filter. Example:
@register.filter
def lower(value):
return value.lower()'

def filter(self, name=None, filter_func=None, **flags):

    if ((name is None) and (filter_func is None)):
        def dec(func):
            return self.filter_function(func, **flags)
        return dec
    elif ((name is not None) and (filter_func is None)):
        if callable(name):
            return self.filter_function(name, **flags)
        else:
            def dec(func):
                return self.filter(name, func, **flags)
            return dec
    elif ((name is not None) and (filter_func is not None)):
        self.filters[name] = filter_func
        for attr in ('expects_localtime', 'is_safe', 'needs_autoescape'):
            if (attr in flags):
                value = flags[attr]
                setattr(filter_func, attr, value)
                if hasattr(filter_func, '_decorated_function'):
                    setattr(filter_func._decorated_function, attr, value)
        filter_func._filter_name = name
        return filter_func
    else:
        raise ValueError(('Unsupported    arguments    to    Library.filter:    (%r,    %r)' % (name, filter_func)))
