Decorate a function call with a commit/rollback and pass the session as the first arg.
339623
def transactional(func):
    
    @wraps(func)
    def wrapper(*args, **kwargs):
        with transaction():
            return func(*args, **kwargs)
    return wrapper
940246
def _chain(first_func, *funcs) -> Callable:
    
    @wraps(first_func)
    def wrapper(*args, **kwargs):
        result = first_func(*args, **kwargs)
        for func in funcs:
            result = func(result)
        return result
    return wrapper
1031869
def memoize(func, cache, num_args):
    

    @wraps(func)
    def wrapper(*args):
        mem_args = args[:num_args]
        if mem_args in cache:
            return cache[mem_args]
        result = func(*args)
        cache[mem_args] = result
        return result

    return wrapper
1125070
def acceptAlias(decoratedFunction):
    """"""
    def wrapper(self, *args, **kwargs):
        SubAssert(isinstance(self, AliasBase))

        if len(args) > 0:
            key = args[0]
            if args[0] in self._aliases.keys():
                key = self._aliases[args[0]]
            return decoratedFunction(self, key, *args[1:], **kwargs)
        return decoratedFunction(self, *args, **kwargs)
    return wrapper
91771
def decorate_function(self, name, decorator):
        
        self.functions[name] = decorator(self.functions[name])
1273181
def reprovision_and_retry(func):
  
  @functools.wraps(func)
  def wrapper(*a, **kw):
    errback = kw.get('errback', None)
    if errback is None:
      def errback(e):
        raise e
    def errback_wrapper(e):
      if isinstance(e, UnknownAppID) and 'INITIAL' in OPTIONS:
        try:
          for initial in OPTIONS['INITIAL']:
            provision(*initial) # retry provisioning the initial setup
          func(*a, **kw) # and try the function once more
        except Exception, new_exc:
          errback(new_exc) # throwing the new exception
      else:
        errback(e) # not an instance of UnknownAppID - nothing we can do here
    kw['errback'] = errback_wrapper
    return func(*a, **kw)
  return wrapper
1041365
def put(self, result, decorated_function, *args, **kwargs):
		
		self.__check(decorated_function, *args, **kwargs)

		ref = weakref.ref(args[0])
		if decorated_function not in self._storage:
			cache_entry = self._cache_record_cls.create(result, decorated_function, *args, **kwargs)
			self._storage[decorated_function] = [{'instance': ref, 'result': cache_entry}]
		else:
			instance_found = False
			for i in self._storage[decorated_function]:
				if i['instance']() == args[0]:
					cache_entry = i['result']
					cache_entry.update(result, *args, **kwargs)
					instance_found = True
					break
			if instance_found is False:
				cache_entry = self._cache_record_cls.create(result, decorated_function, *args, **kwargs)
				self._storage[decorated_function].append({'instance': ref, 'result': cache_entry})

		def finalize_ref():
			if decorated_function in self._storage:
				fn_list = self._storage[decorated_function]
				if len(fn_list) == 1 and fn_list[0]['instance'] == ref:
					del self._storage[decorated_function]

				for i in range(len(fn_list)):
					if fn_list[i]['instance'] == ref:
						fn_list.pop(i)
						return

		weakref.finalize(args[0], finalize_ref)
835106
def patch(self, *args, **kwargs):
        
        return self.session.patch(*args, **self.get_kwargs(**kwargs))
111526
def _wrap(cls, func):
        

        if isinstance(func, cls):
            return func
        return functools.update_wrapper(cls(func), func)
1132880
def retry_and_reset(fn):
    
    @wraps(fn)
    def retry_and_reset_decorator(*args, **kwargs):
        obj = kwargs.get("self", None)

        if not obj:
            obj = args[0]

        try:
            return fn(*args, **kwargs)
        except ConnectionStateError:
            obj._on_close_callback()

        return fn(*args, **kwargs)

    return retry_and_reset_decorator
695437
def wrap_async(func):
    """"""
    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        fut = asyncio.ensure_future(func(*args, **kwargs))
        cur = greenlet.getcurrent()
        def callback(fut):
            try:
                cur.switch(fut.result())
            except BaseException as e:
                cur.throw(e)
        fut.add_done_callback(callback)
        return cur.parent.switch()
    return wrapped
702125
function wrapify(fn, before = noop, after = noop) {
  return function(...args) {
    before.call(this);
    var ret = fn.call(this, ...args);
    after.call(this);
    return ret;
  };
}
512114
def mock_decorator(*args, **kwargs):
    """"""
    def _called_decorator(dec_func):
        @wraps(dec_func)
        def _decorator(*args, **kwargs):
            return dec_func()
        return _decorator
    return _called_decorator
1176365
function decorate (fn) {
  return async function (...args) {
    try {
      return fn.call(this, ...args);
    } catch (err) {
      this.logger && this.logger.error(err.message);
      throw err;
    }
  };
}
869294
function Pack(commit, options, rollCall, command) {
	if (!commit || !options || !rollCall || !command) {
		throw new Error('Invalid arguments: ' + arguments);
	}
	this.commit = commit;
	this.options = options;
	this.rollCall = rollCall;
	this.command = command;
}
1324310
def scoped_session_decorator(func):
    """"""

    @wraps(func)
    def wrapper(*args, **kwargs):
        with sessions_scope(session):
            # The session used in func comes from the funcs globals, but
            # it will be a proxied thread local var from the session
            # registry, and will therefore be identical to the one returned
            # by the context manager above.
            logger.debug("Running worker %s in scoped DB session", func.__name__)
            return func(*args, **kwargs)

    return wrapper
1352406
function wrapCallback( fn, frameLocation ) {
  const traceError = new Error();
  traceError.__location = frameLocation;
  traceError.__previous = currentTraceError;

  return function $wrappedCallback( ...args ) {
    currentTraceError = traceError;
    try {
      return fn.call( this, ...args );
    } catch ( e ) {
      throw e; // we just need the the 'finally'
    } finally {
      currentTraceError = null;
    }
  };
}