當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。