Creates a decorator that can be used as a filter.

    .. warning::
        This is currently not compatible with most other decorators, if
        you are using a decorator that isn't part of `hurler` you should
        take caution.
197354
def filter(filter_creator):
    
    filter_func = [None]

    def function_getter(function):
        if isinstance(function, Filter):
            function.add_filter(filter)

            return function
        else:
            return Filter(
                filter=filter_func[0],
                callback=function,
            )

    def filter_decorator(*args, **kwargs):
        filter_function = filter_creator(*args, **kwargs)

        filter_func[0] = filter_function

        return function_getter

    return filter_decorator
1053829
def _wrap(func, msg):
    """"""

    @functools.wraps(func)
    def new_func(*args, **kwargs):
        warnings.simplefilter('always', DeprecationWarning)     # turn off filter
        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
        warnings.simplefilter('default', DeprecationWarning)    # reset filter
        return func(*args, **kwargs)
    return new_func
549951
def decorator(d):
    
    defaults = d.__defaults__
    if defaults and defaults[0] is None:
        # Can be applied as @decorator or @decorator(kwargs) because
        # first argument is None
        def decorate(fn=None, **kwargs):
            if fn is None:
                return _functools.partial(decorate, **kwargs)
            else:
                decorated = d(fn, **kwargs)
                _functools.update_wrapper(decorated, fn)
                return decorated
    else:
        # Can only be applied as @decorator
        def decorate(fn):
            decorated = d(fn)
            _functools.update_wrapper(decorated, fn)
            return decorated
    _functools.update_wrapper(decorate, d)
    return decorate
1161290
def allow_bare_decorator(cls):
    

    @wraps(cls)
    def wrapper(*args, **kwargs):
        """"Wrapper for real decorator"""

        # If we weren't only passed a bare class, return class instance
        if kwargs or len(args) != 1 or not isclass(args[0]):  # pylint: disable=no-else-return
            return cls(*args, **kwargs)
        # Otherwise, pass call to instance with default values
        else:
            return cls()(args[0])

    return wrapper
1066881
def good_decorator(decorator):
    """""" 
    def new_decorator(f):
        g = decorator(f)
        g.__name__ = f.__name__
        g.__doc__ = f.__doc__
        g.__dict__.update(f.__dict__)
        return g
        
    new_decorator.__name__ = decorator.__name__
    new_decorator.__doc__ = decorator.__doc__
    new_decorator.__dict__.update(decorator.__dict__)

    return new_decorator
1162384
def filter(self, value, table=None):
        '''
        
        '''
        if table is not None:
            filterable = self.filterable_func(value, table)
        else:
            filterable = self.filterable_func(value)
        return filterable
606681
def shh_newFilter(self, to=None, *, topics):
        
        obj = {
            'to': to,
            'topics': topics,
        }
        warnings.warn('deprecated', DeprecationWarning)
        return (yield from self.rpc_call('shh_newFilter', [obj]))
35415
def build_filter(self, filter):
        
        try:
            self.filter = Filter.from_string(filter, self.limit)
        except ValueError:
            raise

        return self
322978
def remove_hairs_decorator(fn=None, hairs=HAIRS):
    
    def decorator_wrapper(fn):
        @wraps(fn)
        def decorator(*args, **kwargs):
            out = fn(*args, **kwargs)

            return remove_hairs(out, hairs)

        return decorator

    if fn:
        return decorator_wrapper(fn)

    return decorator_wrapper
116520
def create(cls, type):
        
        if type == 0: return FilterDropShadow(id)
        elif type == 1: return FilterBlur(id)
        elif type == 2: return FilterGlow(id)
        elif type == 3: return FilterBevel(id)
        elif type == 4: return FilterGradientGlow(id)
        elif type == 5: return FilterConvolution(id)
        elif type == 6: return FilterColorMatrix(id)
        elif type == 7: return FilterGradientBevel(id)
        else:
            raise Exception("Unknown filter type: %d" % type)
558043
def create_dn_in_filter(filter_class, filter_value, helper):
    
    in_filter = FilterFilter()
    in_filter.AddChild(create_dn_wcard_filter(filter_class, filter_value))
    return in_filter
217993
def nowarnings(func):
    
    @functools.wraps(func)
    def new_func(*args, **kwargs):
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            return func(*args, **kwargs)
    return new_func
1000478
def add_inspection(name):
    

    # create the real decorator
    def inspection_inner(func):
        """
        Jishaku inspection decorator
        """

        # pylint: disable=inconsistent-return-statements

        # create an encapsulated version of the inspection that swallows exceptions
        @functools.wraps(func)
        def encapsulated(*args, **kwargs):
            try:
                return func(*args, **kwargs)
            except (TypeError, AttributeError, ValueError, OSError):
                return

        INSPECTIONS.append((name, encapsulated))
        return func
    return inspection_inner
365408
def add_filter(self, func, rules):
        
        if not callable(func):
            raise ValueError("{} is not callable".format(func))
        if not isinstance(rules, list):
            raise ValueError("{} is not list".format(rules))
        if len(rules) > 1:
            for x in rules:
                self.add_filter(func, [x])
        else:
            target_content = rules[0]
            if isinstance(target_content, six.string_types):
                target_content = to_text(target_content)

                def _check_content(message):
                    return message.content == target_content
            elif is_regex(target_content):

                def _check_content(message):
                    return target_content.match(message.content)
            else:
                raise TypeError("%s is not a valid rule" % target_content)
            argc = len(signature(func).parameters.keys())

            @self.text
            def _f(message, session=None):
                _check_result = _check_content(message)
                if _check_result:
                    if isinstance(_check_result, bool):
                        _check_result = None
                    return func(*[message, session, _check_result][:argc])
396497
def allow_filtering(self):
        
        clone = copy.deepcopy(self)
        clone._allow_filtering = True
        return clone
1294359
def filter(self, **kwargs):
        
        readFilter = ReadFilter(**kwargs)
        self._filters.append(readFilter.filter)
        return self
1078788
def add_filter(self, filter):
        
        if not isinstance(filter, AbstractFilter):
            err = 'Filters must be of type {}'.format(AbstractFilter)
            raise InvalidFilter(err)

        if filter not in self.filters:
            self.filters.append(filter)
        return self