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


Python typing.AsyncContextManager方法代码示例

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


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

示例1: test_async_contextmanager

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def test_async_contextmanager(self):
        class NotACM:
            pass
        self.assertIsInstance(ACM(), typing.AsyncContextManager)
        self.assertNotIsInstance(NotACM(), typing.AsyncContextManager)
        @contextlib.contextmanager
        def manager():
            yield 42

        cm = manager()
        self.assertNotIsInstance(cm, typing.AsyncContextManager)
        self.assertEqual(typing.AsyncContextManager[int].__args__, (int,))
        with self.assertRaises(TypeError):
            isinstance(42, typing.AsyncContextManager[int])
        with self.assertRaises(TypeError):
            typing.AsyncContextManager[int, str] 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:18,代码来源:test_typing.py

示例2: aiohttp_request

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def aiohttp_request(method, url, **kwargs) -> typing.AsyncContextManager[aiohttp.ClientResponse]:
    async with aiohttp.ClientSession() as session:
        async with session.request(method, url, ssl=get_ssl_context(), **kwargs) as response:
            yield response 
开发者ID:lbryio,项目名称:lbry-sdk,代码行数:6,代码来源:utils.py

示例3: test_iss_client_session

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def test_iss_client_session():
    assert issubclass(requests.ISSClientSession, typing.AsyncContextManager)
    async with requests.ISSClientSession() as session:
        assert not session.closed
    assert session.closed 
开发者ID:WLM1ke,项目名称:aiomoex,代码行数:7,代码来源:test_requests.py

示例4: __init__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def __init__(
        self, fn: Callable[..., AsyncContextManager[EndpointAPI]], **kwargs: Any
    ) -> None:
        functools.update_wrapper(self, fn)
        self._fn = fn
        self._kwargs = kwargs 
开发者ID:ethereum,项目名称:lahja,代码行数:8,代码来源:initializers.py

示例5: __call__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def __call__(self, engine: EngineAPI) -> AsyncContextManager[EndpointAPI]:
        return self._fn(engine, **self._kwargs)


#
# EndpointAPI.serve
# 
开发者ID:ethereum,项目名称:lahja,代码行数:9,代码来源:initializers.py

示例6: _serve_endpoint

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def _serve_endpoint(
    engine: EngineAPI, config: ConnectionConfig
) -> AsyncContextManager[EndpointAPI]:
    logger.debug(
        "[%s(%s)].serve(%s)", engine.endpoint_class.__name__, config.name, config.path
    )
    return engine.endpoint_class.serve(config) 
开发者ID:ethereum,项目名称:lahja,代码行数:9,代码来源:initializers.py

示例7: _run_endpoint

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def _run_endpoint(engine: EngineAPI, name: str) -> AsyncContextManager[EndpointAPI]:
    logger.debug("[%s(%s)].run()", engine.endpoint_class.__name__, name)
    # EndpointAPI doesn't specify an __init__ so mypy doesn't understand this.
    return engine.endpoint_class(name).run()  # type: ignore 
开发者ID:ethereum,项目名称:lahja,代码行数:6,代码来源:initializers.py

示例8: __init__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def __init__(self, context_managers: Sequence[AsyncContextManager[Any]]) -> None:
        self.cms = tuple(context_managers)
        self.cms_to_exit: Sequence[AsyncContextManager[Any]] = tuple() 
开发者ID:ethereum,项目名称:trinity,代码行数:5,代码来源:contextgroup.py

示例9: _run_background_services

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def _run_background_services(
        services: Sequence[ServiceAPI],
        runner: Callable[[ServiceAPI], AsyncContextManager[ManagerAPI]]
) -> None:
    async with contextlib.AsyncExitStack() as stack:
        managers = tuple([
            await stack.enter_async_context(runner(service))
            for service in services
        ])
        # If any of the services terminate, we do so as well.
        await wait_first([
            asyncio.create_task(manager.wait_finished())
            for manager in managers
        ]) 
开发者ID:ethereum,项目名称:trinity,代码行数:16,代码来源:services.py

示例10: ParagonPeerPairFactory

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def ParagonPeerPairFactory(*,
                           alice_peer_context: ParagonContext = None,
                           alice_remote: NodeAPI = None,
                           alice_private_key: keys.PrivateKey = None,
                           alice_client_version: str = 'alice',
                           bob_peer_context: ParagonContext = None,
                           bob_remote: NodeAPI = None,
                           bob_private_key: keys.PrivateKey = None,
                           bob_client_version: str = 'bob',
                           event_bus: EndpointAPI = None,
                           ) -> AsyncContextManager[Tuple[ParagonPeer, ParagonPeer]]:
    if alice_peer_context is None:
        alice_peer_context = ParagonContext()
    if bob_peer_context is None:
        bob_peer_context = ParagonContext()

    return cast(AsyncContextManager[Tuple[ParagonPeer, ParagonPeer]], PeerPairFactory(
        alice_peer_context=alice_peer_context,
        alice_peer_factory_class=ParagonPeerFactory,
        bob_peer_context=bob_peer_context,
        bob_peer_factory_class=ParagonPeerFactory,
        alice_remote=alice_remote,
        alice_private_key=alice_private_key,
        alice_client_version=alice_client_version,
        bob_remote=bob_remote,
        bob_private_key=bob_private_key,
        bob_client_version=bob_client_version,
        event_bus=event_bus,
    )) 
开发者ID:ethereum,项目名称:trinity,代码行数:31,代码来源:peer.py

示例11: get_connection

# 需要导入模块: import typing [as 别名]
# 或者: from typing import AsyncContextManager [as 别名]
def get_connection(self) -> AsyncContextManager[Connection]:
        async with self._list_lock:
            conn: Connection = await asyncio.shield(self._next_connection())
            # The connection is locked so reconnections don't stack
            async with conn.lock:
                conn.users += 1
        try:
            yield conn
        finally:
            conn.users -= 1 
开发者ID:tulir,项目名称:tgfilestream,代码行数:12,代码来源:paralleltransfer.py


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