def _normalize(args):
# type: (Dict[str, Any]) -> Generator[Tuple[str, str, Any], None, None]
"""Yield a 3-tuple containing the key, a normalized key, and the value.
Args:
args: The arguments parsed by docopt.
Yields:
A 3-tuple that contains the docopt parameter name, the parameter name
normalized to be a valid python identifier, and the value assigned to
the parameter.
"""
for k, v in six.iteritems(args):
nk = re.sub(r'\W|^(?=\d)', '_', k).strip('_').lower()
do_not_shadow = dir(six.moves.builtins) # type: ignore
if keyword.iskeyword(nk) or nk in do_not_shadow:
nk += '_'
_LOGGER.debug('Normalized "%s" to "%s".', k, nk)
yield k, nk, v
评论列表
文章目录