当前位置: 首页>>代码示例>>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;未经允许,请勿转载。