Example #1
0
def _wrap_in_mutation_result(func  # type: Callable[[Any,...],CoreResult]
                             ):
    # type: (...) -> Callable[[Any,...],MutationResult]
    @wraps(func)
    def mutated(*args, **kwargs):
        result = func(*args, **kwargs)
        return get_mutation_result(result)

    mutated.__name__ = func.__name__
    operation_mode.operate_on_doc(mutated, lambda x: func.__doc__)
    return mutated
Example #2
0
def get_result_wrapper(func  # type: Callable[[Any], ResultPrecursor]
                       ):
    # type: (...) -> Callable[[Any], GetResult]
    @wraps(func)
    def wrapped(*args, **kwargs):
        x, options = func(*args, **kwargs)
        return get_wrapped_get_result(x)

    wrapped.__name__ = func.__name__
    operation_mode.operate_on_doc(wrapped, lambda x: func.__doc__)
    return wrapped
Example #3
0
def lookup_in_result_wrapper(func  #type: Callable[[Any], ResultPrecursor]
                             ):
    # type:  (...) -> Callable[[Any], LookupInResult]
    def factory_class(x):
        factory = AsyncLookupInResult if _is_async(x) else LookupInResult
        return factory(x)

    @wraps(func)
    def wrapped(*args, **kwargs):
        x, opts = func(*args, **kwargs)
        return factory_class(x)

    wrapped.__name__ = func.__name__
    operation_mode.operate_on_doc(wrapped, lambda x: func.__doc__)
    return wrapped
Example #4
0
def get_replica_result_wrapper(func  # type: Callable[[Any], ResultPrecursor]
                               ):
    # type: (...) -> Callable[[Any], GetResult]
    def factory_class(x):
        factory = AsyncGetReplicaResult if _is_async(x) else GetReplicaResult
        return factory(x)

    @wraps(func)
    def wrapped(*args, **kwargs):
        x = list(map(factory_class, func(*args, **kwargs)))
        if len(x) > 1:
            return x
        return x[0]

    wrapped.__name__ = func.__name__
    operation_mode.operate_on_doc(wrapped, lambda x: func.__doc__)
    return wrapped
    def __new__(cls, function, *args, **kwargs):
        """
        Mark a function as {}

        :param function: input function
        :return: marked function
        """.format(cls.__name__)

        message = cls.desc+"\n"

        func_name = getattr(function, '__qualname__', function.__name__)

        result = cls.get_final_fn(function, message, func_name)
        operation_mode.operate_on_doc(result,
                                      lambda x:
                                      (function.__doc__+"\n\n" if function.__doc__ else "") + \
                                      "    :warning: " + message % "This")
        return result
Example #6
0
        class DocWrapper(cls):
            @wraps(cls.__init__)
            def __init__(self,  # type: DocWrapper
                         *args,  # type: Any
                         **kwargs  # type: Any
                         ):
                # type: (...) -> None
                try:
                    super(DocWrapper, self).__init__(self, *args, **kwargs)
                except Exception as e:
                    raise

            operation_mode.operate_on_doc(__init__, lambda x: cls.__init__.__doc__.format(**doc_params))