本文整理汇总了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}")
示例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}")
示例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