当前位置: 首页>>代码示例>>Python>>正文


Python promise.is_thenable方法代码示例

本文整理汇总了Python中promise.is_thenable方法的典型用法代码示例。如果您正苦于以下问题:Python promise.is_thenable方法的具体用法?Python promise.is_thenable怎么用?Python promise.is_thenable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在promise的用法示例。


在下文中一共展示了promise.is_thenable方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_social_auth_thenable

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def test_social_auth_thenable(self, *args):

        @decorators.social_auth
        def wrapped(cls, root, info, provider, *args):
            return Promise()

        result = wrapped(TestCase, None, self.info(), 'google-oauth2', 'token')

        self.assertTrue(is_thenable(result)) 
开发者ID:flavors,项目名称:django-graphql-social-auth,代码行数:11,代码来源:test_decorators.py

示例2: social_auth

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def social_auth(f):
    @psa
    @wraps(f)
    def wrapper(cls, root, info, social, **kwargs):
        def on_resolve(payload):
            payload.social = social
            return payload

        result = f(cls, root, info, social, **kwargs)

        if is_thenable(result):
            return Promise.resolve(result).then(on_resolve)
        return on_resolve(result)
    return wrapper 
开发者ID:flavors,项目名称:django-graphql-social-auth,代码行数:16,代码来源:decorators.py

示例3: execute

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def execute(self, *args, **kwargs):
        executed = self.schema.execute(*args, **dict(self.execute_options, **kwargs))
        if is_thenable(executed):
            return Promise.resolve(executed).then(self.format_result)

        return self.format_result(executed) 
开发者ID:graphql-python,项目名称:graphene,代码行数:8,代码来源:__init__.py

示例4: connection_resolver

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def connection_resolver(cls, resolver, connection_type, model, root, info, **args):
        resolved = resolver(root, info, **args)

        on_resolve = partial(cls.resolve_connection, connection_type, model, info, args)
        if is_thenable(resolved):
            return Promise.resolve(resolved).then(on_resolve)

        return on_resolve(resolved) 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:10,代码来源:fields.py

示例5: test_coroutine_is_thenable

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def test_coroutine_is_thenable():
    async def my_coroutine():
        await sleep(.01)
        return True

    assert is_thenable(my_coroutine()) 
开发者ID:syrusakbary,项目名称:promise,代码行数:8,代码来源:test_awaitable_35.py

示例6: test_benchmark_is_thenable_basic_type

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def test_benchmark_is_thenable_basic_type(benchmark):
    def create_promise():
        return is_thenable(True)

    result = benchmark(create_promise)
    assert result == False 
开发者ID:syrusakbary,项目名称:promise,代码行数:8,代码来源:test_benchmark.py

示例7: test_benchmark_is_thenable_custom_type

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def test_benchmark_is_thenable_custom_type(benchmark):
    class MyType(object):
        pass

    my_type_instance = MyType()

    def create_promise():
        return is_thenable(my_type_instance)

    result = benchmark(create_promise)
    assert result == False 
开发者ID:syrusakbary,项目名称:promise,代码行数:13,代码来源:test_benchmark.py

示例8: execute_fields

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def execute_fields(
    exe_context,  # type: ExecutionContext
    parent_type,  # type: GraphQLObjectType
    source_value,  # type: Any
    fields,  # type: DefaultOrderedDict
    path,  # type: List[Union[int, str]]
    info,  # type: Optional[ResolveInfo]
):
    # type: (...) -> Union[Dict, Promise[Dict]]
    contains_promise = False

    final_results = OrderedDict()

    for response_name, field_asts in fields.items():
        result = resolve_field(
            exe_context,
            parent_type,
            source_value,
            field_asts,
            info,
            path + [response_name],
        )
        if result is Undefined:
            continue

        final_results[response_name] = result
        if is_thenable(result):
            contains_promise = True

    if not contains_promise:
        return final_results

    return promise_for_dict(final_results) 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:35,代码来源:executor.py

示例9: complete_value_catching_error

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def complete_value_catching_error(
    exe_context,  # type: ExecutionContext
    return_type,  # type: Any
    field_asts,  # type: List[Field]
    info,  # type: ResolveInfo
    path,  # type: List[Union[int, str]]
    result,  # type: Any
):
    # type: (...) -> Any
    # If the field type is non-nullable, then it is resolved without any
    # protection from errors.
    if isinstance(return_type, GraphQLNonNull):
        return complete_value(exe_context, return_type, field_asts, info, path, result)

    # Otherwise, error protection is applied, logging the error and
    # resolving a null value for this field if one is encountered.
    try:
        completed = complete_value(
            exe_context, return_type, field_asts, info, path, result
        )
        if is_thenable(completed):

            def handle_error(error):
                # type: (Union[GraphQLError, GraphQLLocatedError]) -> Optional[Any]
                traceback = completed._traceback  # type: ignore
                exe_context.report_error(error, traceback)
                return None

            return completed.catch(handle_error)

        return completed
    except Exception as e:
        traceback = sys.exc_info()[2]
        exe_context.report_error(e, traceback)
        return None 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:37,代码来源:executor.py

示例10: complete_list_value

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def complete_list_value(
    exe_context,  # type: ExecutionContext
    return_type,  # type: GraphQLList
    field_asts,  # type: List[Field]
    info,  # type: ResolveInfo
    path,  # type: List[Union[int, str]]
    result,  # type: Any
):
    # type: (...) -> List[Any]
    """
    Complete a list value by completing each item in the list with the inner type
    """
    assert isinstance(result, Iterable), (
        "User Error: expected iterable, but did not find one " + "for field {}.{}."
    ).format(info.parent_type, info.field_name)

    item_type = return_type.of_type
    completed_results = []
    contains_promise = False

    index = 0
    for item in result:
        completed_item = complete_value_catching_error(
            exe_context, item_type, field_asts, info, path + [index], item
        )
        if not contains_promise and is_thenable(completed_item):
            contains_promise = True

        completed_results.append(completed_item)
        index += 1

    return (
        Promise.all(completed_results)  # type: ignore
        if contains_promise
        else completed_results
    ) 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:38,代码来源:executor.py

示例11: execute_fields_serially

# 需要导入模块: import promise [as 别名]
# 或者: from promise import is_thenable [as 别名]
def execute_fields_serially(
    exe_context,  # type: ExecutionContext
    parent_type,  # type: GraphQLObjectType
    source_value,  # type: Any
    path,  # type: List
    fields,  # type: DefaultOrderedDict
):
    # type: (...) -> Promise
    def execute_field_callback(results, response_name):
        # type: (Dict, str) -> Union[Dict, Promise[Dict]]
        field_asts = fields[response_name]
        result = resolve_field(
            exe_context,
            parent_type,
            source_value,
            field_asts,
            None,
            path + [response_name],
        )
        if result is Undefined:
            return results

        if is_thenable(result):

            def collect_result(resolved_result):
                # type: (Dict) -> Dict
                results[response_name] = resolved_result
                return results

            return result.then(collect_result, None)

        results[response_name] = result
        return results

    def execute_field(prev_promise, response_name):
        # type: (Promise, str) -> Promise
        return prev_promise.then(
            lambda results: execute_field_callback(results, response_name)
        )

    return functools.reduce(
        execute_field, fields.keys(), Promise.resolve(collections.OrderedDict())
    ) 
开发者ID:graphql-python,项目名称:graphql-core-legacy,代码行数:45,代码来源:executor.py


注:本文中的promise.is_thenable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。