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


Python enum.Flag方法代码示例

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


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

示例1: wait_flag

# 需要导入模块: import enum [as 别名]
# 或者: from enum import Flag [as 别名]
def wait_flag(
        flag: Optional[Flag],
) -> Any:
    """
    Wait for a flag to be raised.

    Non-asyncio primitives are generally not our worry,
    but we support them for convenience.
    """
    if flag is None:
        pass
    elif isinstance(flag, asyncio.Future):
        return await flag
    elif isinstance(flag, asyncio.Event):
        return await flag.wait()
    elif isinstance(flag, concurrent.futures.Future):
        loop = asyncio.get_running_loop()
        return await loop.run_in_executor(None, flag.result)
    elif isinstance(flag, threading.Event):
        loop = asyncio.get_running_loop()
        return await loop.run_in_executor(None, flag.wait)
    else:
        raise TypeError(f"Unsupported type of a flag: {flag!r}") 
开发者ID:zalando-incubator,项目名称:kopf,代码行数:25,代码来源:primitives.py

示例2: raise_flag

# 需要导入模块: import enum [as 别名]
# 或者: from enum import Flag [as 别名]
def raise_flag(
        flag: Optional[Flag],
) -> None:
    """
    Raise a flag.

    Non-asyncio primitives are generally not our worry,
    but we support them for convenience.
    """
    if flag is None:
        pass
    elif isinstance(flag, asyncio.Future):
        flag.set_result(None)
    elif isinstance(flag, asyncio.Event):
        flag.set()
    elif isinstance(flag, concurrent.futures.Future):
        flag.set_result(None)
    elif isinstance(flag, threading.Event):
        flag.set()
    else:
        raise TypeError(f"Unsupported type of a flag: {flag!r}") 
开发者ID:zalando-incubator,项目名称:kopf,代码行数:23,代码来源:primitives.py

示例3: group_by_contract

# 需要导入模块: import enum [as 别名]
# 或者: from enum import Flag [as 别名]
def group_by_contract(plugins: Iterable[Plugin]) -> DefaultDict[Contract, List[Plugin]]:
    """
    Groups plugins in lists according to their contracts.
    Each plugin is found in as many lists as it implements base contracts.
    Lists keep the order of the original plugins iterable.
    """
    res = defaultdict(list)
    for p in plugins:
        c = contract(p)
        for bc in _BASE_CONTRACTS:
            if c & bc:  # Contract is an enum.Flag: & computes the intersection.
                res[bc].append(p)
    return res 
开发者ID:zalando-incubator,项目名称:transformer,代码行数:15,代码来源:contracts.py


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