-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathutil.py
More file actions
26 lines (19 loc) · 686 Bytes
/
util.py
File metadata and controls
26 lines (19 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""OpenAPI core util module"""
from itertools import chain
from typing import Any
from typing import Iterable
BOOLEAN_TRUE_VALUES = ("y", "yes", "t", "true", "on", "1")
BOOLEAN_FALSE_VALUES = ("n", "no", "f", "false", "off", "0")
def forcebool(val: Any) -> bool:
if isinstance(val, str):
val = val.lower()
if val in BOOLEAN_TRUE_VALUES:
return True
elif val in BOOLEAN_FALSE_VALUES:
return False
else:
raise ValueError(f"invalid truth value {val!r}")
return bool(val)
def chainiters(*lists: Iterable[Any]) -> Iterable[Any]:
iters = map(lambda l: l and iter(l) or [], lists)
return chain(*iters)