Returns a copy of a function.

    :param func: The function to copy.
    :returns: The copied function.
3177
def copy_func(func: Callable) -> Callable:
    
    copied = types.FunctionType(
        func.__code__, func.__globals__, name=func.__name__,
        argdefs=func.__defaults__, closure=func.__closure__)
    copied = functools.update_wrapper(copied, func)
    copied.__kwdefaults__ = func.__kwdefaults__
    return copied
58119
def _writer(func):
    

    name = func.__name__
    return property(fget=lambda self: getattr(self, '_%s' % name), fset=func)
973056
def func_call(self, t):
        
        func, params = t
        func_name = func.value
        func.value = "({}({}))".format(func_name, params)
        return func
1353928
def pipe_util(func):
    
    @wraps(func)
    def pipe_util_wrapper(function, *args, **kwargs):
        if isinstance(function, XObject):
            function = ~function

        original_function = function

        if args or kwargs:
            function = xpartial(function, *args, **kwargs)

        name = lambda: '%s(%s)' % (get_name(func), ', '.join(
            filter(None, (get_name(original_function), repr_args(*args, **kwargs)))))

        f = func(function)

        result = pipe | set_name(name, f)

        # if the util defines an 'attrs' mapping, copy it as attributes
        # to the result
        attrs = getattr(f, 'attrs', {})
        for k, v in dict_items(attrs):
            setattr(result, k, v)

        return result

    return pipe_util_wrapper
109767
def synchronized(func):
    
    @wraps(func)
    def wrapped(self, *args, **kwargs):
        try:
            rlock = self._sync_lock
        except AttributeError:
            from multiprocessing import RLock
            rlock = self.__dict__.setdefault('_sync_lock', RLock())
        with rlock:
            return func(self, *args, **kwargs)
    return wrapped
1062162
function copyFunction(original)
{
  // clone original function
  var target = fulcon(original);

  // copy it's "static" methods
  copy(target, original);
  // duplicate prototype methods
  copy(target.prototype, original.prototype);

  // add instance reference to the it's own constructor
  Object.defineProperty(target.prototype, 'constructor', {
    value       : target,
    writable    : true,
    enumerable  : false,
    configurable: true
  });

  return target;
}
397325
def dict_copy(func):
    ""
    def proxy(*args, **kwargs):
        new_args = []
        new_kwargs = {}
        for var in kwargs:
            if isinstance(kwargs[var], dict):
                new_kwargs[var] = dict(kwargs[var])
            else:
                new_kwargs[var] = kwargs[var]
        for arg in args:
            if isinstance(arg, dict):
                new_args.append(dict(arg))
            else:
                new_args.append(arg)
        return func(*new_args, **new_kwargs)
    return proxy
1091160
def _get_remote_method(self, funcname):
        

        func = getattr(self, funcname)
        if not callable(func) or not getattr(func, '_remote', False):
            raise AttributeError("%r object has no attribute %r" %
                                 (self.__class__.__name__, funcname))

        return func
133968
function toSource(func) {
  if (func != null) {
    try {
      return funcToString$2.call(func);
    } catch (e) {}
    try {
      return (func + '');
    } catch (e) {}
  }
  return '';
}
219981
def memoize(function):
    
    cache = {}
    @functools.wraps(function)
    def _memoize(*args):
        if args in cache:
            return cache[args]
        result = function(*args)
        cache[args] = result
        return result
    return function
1204913
def transform(self, func):
        
        if func.__code__.co_argcount == 1:
            oldfunc = func
            func = lambda t, rdd: oldfunc(rdd)
        assert func.__code__.co_argcount == 2, "func should take one or two arguments"
        return TransformedDStream(self, func)
1038103
def copy(self):
        

        copy = MOC(name=self.name, mocid=self.id,
                   origin=self.origin, moctype=self.type)

        copy += self

        return copy
919202
def decorator(caller, func=None):
    
    if func is None: # returns a decorator
        fun = FunctionMaker(caller)
        first_arg = inspect.getargspec(caller)[0][0]
        src = 'def %s(%s): return _call_(caller, %s)' % (
            caller.__name__, first_arg, first_arg)
        return fun.make(src, dict(caller=caller, _call_=decorator),
                        undecorated=caller)
    else: # returns a decorated function
        fun = FunctionMaker(func)
        src = """def %(name)s(%(signature)s):
    return _call_(_func_, %(signature)s)"""
        return fun.make(src, dict(_func_=func, _call_=caller), undecorated=func)
893733
def synchronized(func):  # pylint: disable=invalid-name
  """"""
  @functools.wraps(func)
  def synchronized_method(self, *args, **kwargs):
    """Wrapper to return."""
    if not hasattr(self, '_lock'):
      if func.__name__ in type(self).__dict__:
        hint = ''
      else:
        hint = (' Might be missing call to super in %s.__init__?' %
                type(self).__name__)
      raise RuntimeError('Can\'t synchronize method `%s` of %s without '
                         'attribute `_lock`.%s' %
                         (func.__name__, type(self).__name__, hint))
    with self._lock:  # pylint: disable=protected-access
      return func(self, *args, **kwargs)
  return synchronized_method
1142452
def __get_function_or_ex_function(self, func_name):
        
        # try function name as given
        try:
            return getattr(self.driver, func_name)
        except AttributeError:
            pass
        # try prefixing name with `ex_`
        try:
            return getattr(self.driver, 'ex_' + func_name)
        except AttributeError:
            pass
        # no such function
        raise AttributeError(
            "No function named `{0}` or `{1}` in class `{2}`"
            .format(func_name, 'ex_'+func_name, self.__class__.__name__))
932627
def produce(self, func):
        
        # 声明队列
        if not self.task_queue:
            self.ch.queue_declare(queue=self.task_queue, durable=self.durable)
        func(self)
657832
def get_function(self):
        
        if not hasattr(self, '_function'):
            try:
                modname, funcname = self.function.rsplit('.', 1)
                mod = import_module(modname)
                self._function = getattr(mod, funcname)
            except (ImportError, AttributeError, ValueError), err:
                raise ProcessorConfigurationError(err)

        return self._function