Decorator that add attributes into func.

    Added attributes can be access outside via function's `func_dict` property.
481971
def attr(**context):
    
    #TODO(Jim Zhan) FIXME
    def decorator(func):
        def wrapped_func(*args, **kwargs):
            for key, value in context.items():
                print key, value
            return func(*args, **kwargs)
        return wraps(func)(decorator)
    return decorator
463487
def add_property(attribute, type):
    
    def decorator(cls):
        """Decorator
        """
        private = "_" + attribute

        def getAttr(self):
            """Property getter
            """
            if getattr(self, private) is None:
                setattr(self, private, type())
            return getattr(self, private)

        def setAttr(self, value):
            """Property setter
            """
            setattr(self, private, value)

        setattr(cls, attribute, property(getAttr, setAttr))
        setattr(cls, private, None)
        return cls

    return decorator
1156580
def func_attr(f, attr):
    
    if hasattr(f, 'func_%s' % attr):
        return getattr(f, 'func_%s' % attr)
    elif hasattr(f, '__%s__' % attr):
        return getattr(f, '__%s__' % attr)
    else:
        raise ValueError('Object %s has no attr' % (str(f), attr))
75709
def argument(*args, **kwargs):
    
    def decorator(f):
        if not hasattr(f, '_arguments'):
            f._arguments = []
        if not hasattr(f, '_argnames'):
            f._argnames = []
        f._arguments.append((args, kwargs))
        f._argnames.append(_get_dest(*args, **kwargs))
        return f
    return decorator
990473
def accessible(f):
    
    @wraps(f)
    def wrapper(*args, **kwargs):
        print 'KWARGS= ', kwargs
        setattr(args[0], kwargs['name'], args[1])
        print "property: ", str(getattr(args[0], kwargs['name']))
        return f(*args, **kwargs)
    return wrapper
1049949
def cached_property(func):
    """"""
    @functools.wraps(func)
    def cached_func(self):
        cacheattr = '_{}'.format(func.func_name)
        try:
            return getattr(self, cacheattr)
        except AttributeError:
            value = func(self)
            setattr(self, cacheattr, value)
            return value
    return property(cached_func)
91771
def decorate_function(self, name, decorator):
        
        self.functions[name] = decorator(self.functions[name])
871637
def call(self, func, *args, **kwargs):
        
        wrapped = self.wrap(func)
        return wrapped(*args, **kwargs)
1281226
def settings_view_decorator(function):
    

    dec = settings.CLOUD_BROWSER_VIEW_DECORATOR

    # Trade-up string to real decorator.
    if isinstance(dec, str):
        # Split into module and decorator strings.
        mod_str, _, dec_str = dec.rpartition('.')
        if not (mod_str and dec_str):
            raise ImportError("Unable to import module: %s" % mod_str)

        # Import and try to get decorator function.
        mod = import_module(mod_str)
        if not hasattr(mod, dec_str):
            raise ImportError("Unable to import decorator: %s" % dec)

        dec = getattr(mod, dec_str)

    if dec and callable(dec):
        return dec(function)

    return function
272803
def classattribute(func):
    
    attr = abc.abstractmethod(func)
    attr.__iclassattribute__ = True
    attr = _property(attr)
    return attr
359939
def add_callback(self, func):
        
        if func is None: return
        func_list = to_list(func)

        if not hasattr(self, 'callback_list'):
            self.callback_list = func_list
        else:
            self.callback_list.extend(func_list)
639940
def add_arg_scope(func):
  
  @functools.wraps(func)
  def func_with_args(*args, **kwargs):
    current_scope = _current_arg_scope()
    current_args = kwargs
    key_func = (func.__module__, func.__name__)
    if key_func in current_scope:
      current_args = current_scope[key_func].copy()
      current_args.update(kwargs)
    return func(*args, **current_args)
  _add_op(func)
  return func_with_args
1122461
def add_argument(*args, **kwargs):
    

    def decorator(func):
        func = ScriptAdaptor._wrap(func)
        func._add_argument(args, kwargs)
        return func
    return decorator
1171986
def add_function_attribute(self, attr):
        
        if not self.is_function:
            raise ValueError('expected function value, got %s' % (self._kind,))
        attrname = str(attr)
        attrval = ffi.lib.LLVMPY_GetEnumAttributeKindForName(
            _encode_string(attrname), len(attrname))
        if attrval == 0:
            raise ValueError('no such attribute {!r}'.format(attrname))
        ffi.lib.LLVMPY_AddFunctionAttr(self, attrval)
122098
def apply_kwargs(func, **kwargs):
    
    new_kwargs = {}
    params = signature(func).parameters
    for param_name in params.keys():
        if param_name in kwargs:
            new_kwargs[param_name] = kwargs[param_name]
    return func(**new_kwargs)
606480
def allow_create(function):
    
    @wraps(function)
    def _wrapped_func(*args, **kwargs):
        form = args[0]
        # If this argument is not a form, there are a lot of chances that
        # you didn't decorate the right method.
        # This decorator is only to be used decorating "form_valid()"
        if isinstance(form, (Form, ModelForm)):
            # If the form is not valid, don't try to create new values
            if not form.is_valid():
                return function(*args, **kwargs)

            for k, field in form.fields.items():
                if getattr(field, 'create', False) \
                        and getattr(field, '_new_values', None):
                    new_values = field.create_new_values()
                    # update the field value
                    form.cleaned_data[k] = form.cleaned_data[k] | new_values

        return function(*args, **kwargs)
    return _wrapped_func
31522
def wrap(self, function):
        
        func = inspect.getfullargspec(function)
        needed_arguments = func.args + func.kwonlyargs

        @wraps(function)
        def wrapper(*args, **kwargs):
            arguments = kwargs.copy()
            missing_arguments = needed_arguments - arguments.keys()
            for arg in missing_arguments:
                try:
                    arguments[arg] = self._get_argument(arg)
                except KeyError:
                    pass
            return function(*args, **arguments)

        return wrapper