Adds the function f to a dictionary of JSON RPC methods.

        :param callable f: Method to be exposed
        :return:
975940
def add_handler(self, f):
        
        if f.__name__.startswith('rpc_'):
            raise ValueError("Server method names cannot start with rpc_.")
        self._json_rpc_methods[f.__name__] = f
        return f
956297
def json(func):
    
    if inspect.isclass(func):
        apply_function_to_members(func, json)
        return func
    else:
        @functools.wraps(func)
        def decorated_view(*args, **kwargs):
            data = func(*args, **kwargs)
            return _build_response(data, jsonify)
        return decorated_view
636816
def apply(self, fn, *a, **kw):
        """"""
        args, kwargs = self.prepare_callable(fn)
        args += a; kwargs.update(kw)
        return fn(*args, **kwargs)
640854
def p_functioncall(self, p):
        ''
        p[0] = FunctionCall(p[1], p[3], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
368595
def _start_callables(self, row, callables):
        
        id_vals = {c: row[c] for c in self.ids}

        def callback(tab, cols, result):
            if isinstance(result, Mapping):
                pass
            elif isinstance(result, tuple):
                result = dict(zip(cols, result))
            elif len(cols) == 1:
                # Don't bother raising an exception if cols != 1
                # because it would be lost in the thread.
                result = {cols[0]: result}
            result.update(id_vals)
            tab._write(result)

        if self._pool is None:
            self._pool = Pool()
        if self._lock is None:
            self._lock = multiprocessing.Lock()

        for cols, fn in callables:
            cb_func = partial(callback, self, cols)

            gen = None
            if inspect.isgeneratorfunction(fn):
                gen = fn()
            elif inspect.isgenerator(fn):
                gen = fn

            if gen:
                def callback_for_each():
                    for i in gen:
                        cb_func(i)
                self._pool.apply_async(callback_for_each)
            else:
                self._pool.apply_async(fn, callback=cb_func)
751129
def add_function(self, func):
        
        try:
            # func_code does not exist in Python3
            code = func.__code__
        except AttributeError:
            import warnings
            warnings.warn("Could not extract a code object for the object %r"
                          % (func,))
            return
        if code not in self.code_map:
            self.code_map[code] = {}
            self.functions.append(func)
314104
def from_file(cls, f):
        

        with open_file_like(f, 'r') as fp:
            return cls(json.load(fp))
131684
def get_func(func, aliasing, implementations):
    
    try:
        func_str = aliasing[func]
    except KeyError:
        if callable(func):
            return func
    else:
        if func_str in implementations:
            return func_str
        if func_str.startswith('nan') and \
                func_str[3:] in funcs_no_separate_nan:
            raise ValueError("%s does not have a nan-version".format(func_str[3:]))
        else:
            raise NotImplementedError("No such function available")
    raise ValueError("func %s is neither a valid function string nor a "
                     "callable object".format(func))
388059
def gcall(func, *args, **kwargs):
    
    def idle():
        with gdk.lock:
            return bool(func(*args, **kwargs))
    return gobject.idle_add(idle)
859149
def func_factory(p, method: str) -> callable:
    

    def callback(pretty: bool = False):
        res = getattr(p, method)
        dump = partial(json.dumps, indent=4) if pretty else partial(json.dumps)
        click.echo(dump(res))

    return callback
357323
def _add_function(self, func, identify_observed):
        

        key = self.make_key(func)
        if key not in self.observers:
            self.observers[key] = ObserverFunction(
                func, identify_observed, (key, self.observers))
            return True
        else:
            return False
1200793
def _callable_func(self, func, axis, *args, **kwargs):
        

        def callable_apply_builder(df, axis=0):
            if not axis:
                df.index = index
                df.columns = pandas.RangeIndex(len(df.columns))
            else:
                df.columns = index
                df.index = pandas.RangeIndex(len(df.index))
            result = df.apply(func, axis=axis, *args, **kwargs)
            return result

        index = self.index if not axis else self.columns
        func_prepared = self._build_mapreduce_func(callable_apply_builder, axis=axis)
        result_data = self._map_across_full_axis(axis, func_prepared)
        return self._post_process_apply(result_data, axis)
471264
function functionBind(f, obj) {
  if (NATIVE_FUNCTION_BIND) {
    return NATIVE_FUNCTION_BIND.call(f, obj);
  }

  return function boundFunction_() {
    return f.apply(obj, arguments);
  };
}
1142554
def put(func: Callable, allowed_exceptions: List = None,
        title: str = None, req_obj_type: Callable = None) -> HTTPMethod:
    
    return HTTPMethod('put', func, allowed_exceptions=allowed_exceptions,
                      title=title, req_obj_type=req_obj_type)
869546
def add_functions(spec_dict: Mapping[str, Any]) -> Mapping[str, Any]:
    

    # Class 'Mapping' does not define '__setitem__', so the '[]' operator cannot be used on its instances
    spec_dict["functions"]["list"] = []
    spec_dict["functions"]["list_long"] = []
    spec_dict["functions"]["list_short"] = []

    spec_dict["functions"]["primary"] = {}
    spec_dict["functions"]["primary"]["list_long"] = []
    spec_dict["functions"]["primary"]["list_short"] = []

    spec_dict["functions"]["modifier"] = {}
    spec_dict["functions"]["modifier"]["list_long"] = []
    spec_dict["functions"]["modifier"]["list_short"] = []

    spec_dict["functions"]["to_short"] = {}
    spec_dict["functions"]["to_long"] = {}

    for func_name in spec_dict["functions"]["info"]:

        abbreviated_name = spec_dict["functions"]["info"][func_name]["abbreviation"]

        spec_dict["functions"]["list"].extend((func_name, abbreviated_name))

        spec_dict["functions"]["list_long"].append(func_name)
        spec_dict["functions"]["list_short"].append(abbreviated_name)

        if spec_dict["functions"]["info"][func_name]["type"] == "primary":
            spec_dict["functions"]["primary"]["list_long"].append(func_name)
            spec_dict["functions"]["primary"]["list_short"].append(abbreviated_name)
        else:
            spec_dict["functions"]["modifier"]["list_long"].append(func_name)
            spec_dict["functions"]["modifier"]["list_short"].append(abbreviated_name)

        spec_dict["functions"]["to_short"][abbreviated_name] = abbreviated_name
        spec_dict["functions"]["to_short"][func_name] = abbreviated_name

        spec_dict["functions"]["to_long"][abbreviated_name] = func_name
        spec_dict["functions"]["to_long"][func_name] = func_name

    return spec_dict
577000
def get_func_args(func):
    
    if isinstance(func, functools.partial):
        return _signature(func.func)
    if inspect.isfunction(func) or inspect.ismethod(func):
        return _signature(func)
    # Callable class
    return _signature(func.__call__)
795986
def function_to_serializable_representation(fn):
    
    if type(fn) not in (FunctionType, BuiltinFunctionType):
        raise ValueError(
            "Can't serialize %s : %s, must be globally defined function" % (
                fn, type(fn),))

    if hasattr(fn, "__closure__") and fn.__closure__ is not None:
        raise ValueError("No serializable representation for closure %s" % (fn,))

    return {"__module__": get_module_name(fn), "__name__": fn.__name__}