當前位置: 首頁>>代碼示例>>Python>>正文


Python abc.AsyncIterable方法代碼示例

本文整理匯總了Python中collections.abc.AsyncIterable方法的典型用法代碼示例。如果您正苦於以下問題:Python abc.AsyncIterable方法的具體用法?Python abc.AsyncIterable怎麽用?Python abc.AsyncIterable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在collections.abc的用法示例。


在下文中一共展示了abc.AsyncIterable方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _async_forward

# 需要導入模塊: from collections import abc [as 別名]
# 或者: from collections.abc import AsyncIterable [as 別名]
def _async_forward(async_chunks: AsyncIterable,
                         out: Optional[Union[TeeCapture, IO[str]]]
                        ) -> Optional[str]:
    """Prints/captures output from the given asynchronous iterable.

    Args:
        async_chunks: An asynchronous source of bytes or str.
        out: Where to put the chunks.

    Returns:
        The complete captured output, or else None if the out argument wasn't a
        TeeCapture instance.
    """
    capture = isinstance(out, TeeCapture)
    out_pipe = out.out_pipe if isinstance(out, TeeCapture) else out

    chunks: Optional[List[str]] = [] if capture else None
    async for chunk in async_chunks:
        if not isinstance(chunk, str):
            chunk = chunk.decode()
        if out_pipe:
            print(chunk, file=out_pipe, end='')
        if chunks is not None:
            chunks.append(chunk)

    return ''.join(chunks) if chunks is not None else None 
開發者ID:quantumlib,項目名稱:OpenFermion,代碼行數:28,代碼來源:shell_tools.py

示例2: test_AsyncIterable

# 需要導入模塊: from collections import abc [as 別名]
# 或者: from collections.abc import AsyncIterable [as 別名]
def test_AsyncIterable(self):
        class AI:
            async def __aiter__(self):
                return self
        self.assertTrue(isinstance(AI(), AsyncIterable))
        self.assertTrue(issubclass(AI, AsyncIterable))
        # Check some non-iterables
        non_samples = [None, object, []]
        for x in non_samples:
            self.assertNotIsInstance(x, AsyncIterable)
            self.assertFalse(issubclass(type(x), AsyncIterable), repr(type(x)))
        self.validate_abstract_methods(AsyncIterable, '__aiter__')
        self.validate_isinstance(AsyncIterable, '__aiter__') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:15,代碼來源:test_collections.py

示例3: __init__

# 需要導入模塊: from collections import abc [as 別名]
# 或者: from collections.abc import AsyncIterable [as 別名]
def __init__(self,
                 value: _AsyncIterable,
                 *args: Any,
                 **kwargs: Any) -> None:
        if not isinstance(value, AsyncIterable):
            raise TypeError("value argument must support "
                            "collections.abc.AsyncIterablebe interface, "
                            "got {!r}".format(type(value)))

        if 'content_type' not in kwargs:
            kwargs['content_type'] = 'application/octet-stream'

        super().__init__(value, *args, **kwargs)

        self._iter = value.__aiter__() 
開發者ID:TouwaStar,項目名稱:Galaxy_Plugin_Bethesda,代碼行數:17,代碼來源:payload.py

示例4: test_AsyncIterable

# 需要導入模塊: from collections import abc [as 別名]
# 或者: from collections.abc import AsyncIterable [as 別名]
def test_AsyncIterable(self):
        class AI:
            def __aiter__(self):
                return self
        self.assertTrue(isinstance(AI(), AsyncIterable))
        self.assertTrue(issubclass(AI, AsyncIterable))
        # Check some non-iterables
        non_samples = [None, object, []]
        for x in non_samples:
            self.assertNotIsInstance(x, AsyncIterable)
            self.assertFalse(issubclass(type(x), AsyncIterable), repr(type(x)))
        self.validate_abstract_methods(AsyncIterable, '__aiter__')
        self.validate_isinstance(AsyncIterable, '__aiter__') 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:15,代碼來源:test_collections.py


注:本文中的collections.abc.AsyncIterable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。