本文整理汇总了Python中xonsh.tools.to_bool函数的典型用法代码示例。如果您正苦于以下问题:Python to_bool函数的具体用法?Python to_bool怎么用?Python to_bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_bool函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ensure_shell
def ensure_shell(shell):
"""Ensures that a mapping follows the shell specification."""
if not isinstance(shell, MutableMapping):
shell = dict(shell)
shell_keys = set(shell.keys())
if not (shell_keys <= VALID_SHELL_PARAMS):
msg = 'unknown shell keys: {0}'
raise KeyError(msg.format(shell_keys - VALID_SHELL_PARAMS))
shell['shell'] = ensure_string(shell['shell'])
if 'interactive' in shell_keys:
shell['interactive'] = to_bool(shell['interactive'])
if 'login' in shell_keys:
shell['login'] = to_bool(shell['login'])
if 'envcmd' in shell_keys:
shell['envcmd'] = eunsure_string(shell['envcmd'])
if 'aliascmd' in shell_keys:
shell['aliascmd'] = eunsure_string(shell['aliascmd'])
if 'extra_args' in shell_keys and not isinstance(shell['extra_args'], tuple):
shell['extra_args'] = tuple(map(ensure_string, shell['extra_args']))
if 'currenv' in shell_keys and not isinstance(shell['currenv'], tuple):
ce = shell['currenv']
if isinstance(ce, Mapping):
ce = tuple([(ensure_string(k), v) for k, v in ce.items()])
elif isinstance(ce, Sequence):
ce = tuple([(ensure_string(k), v) for k, v in ce])
else:
raise RuntimeError('unrecognized type for currenv')
shell['currenv'] = ce
if 'safe' in shell_keys:
shell['safe'] = to_bool(shell['safe'])
return shell
开发者ID:ArRolin,项目名称:gitsome,代码行数:31,代码来源:foreign_shells.py
示例2: ensure_shell
def ensure_shell(shell):
"""Ensures that a mapping follows the shell specification."""
if not isinstance(shell, cabc.MutableMapping):
shell = dict(shell)
shell_keys = set(shell.keys())
if not (shell_keys <= VALID_SHELL_PARAMS):
msg = "unknown shell keys: {0}"
raise KeyError(msg.format(shell_keys - VALID_SHELL_PARAMS))
shell["shell"] = ensure_string(shell["shell"]).lower()
if "interactive" in shell_keys:
shell["interactive"] = to_bool(shell["interactive"])
if "login" in shell_keys:
shell["login"] = to_bool(shell["login"])
if "envcmd" in shell_keys:
shell["envcmd"] = (
None if shell["envcmd"] is None else ensure_string(shell["envcmd"])
)
if "aliascmd" in shell_keys:
shell["aliascmd"] = (
None if shell["aliascmd"] is None else ensure_string(shell["aliascmd"])
)
if "extra_args" in shell_keys and not isinstance(shell["extra_args"], tuple):
shell["extra_args"] = tuple(map(ensure_string, shell["extra_args"]))
if "currenv" in shell_keys and not isinstance(shell["currenv"], tuple):
ce = shell["currenv"]
if isinstance(ce, cabc.Mapping):
ce = tuple([(ensure_string(k), v) for k, v in ce.items()])
elif isinstance(ce, cabc.Sequence):
ce = tuple([(ensure_string(k), v) for k, v in ce])
else:
raise RuntimeError("unrecognized type for currenv")
shell["currenv"] = ce
if "safe" in shell_keys:
shell["safe"] = to_bool(shell["safe"])
if "prevcmd" in shell_keys:
shell["prevcmd"] = ensure_string(shell["prevcmd"])
if "postcmd" in shell_keys:
shell["postcmd"] = ensure_string(shell["postcmd"])
if "funcscmd" in shell_keys:
shell["funcscmd"] = (
None if shell["funcscmd"] is None else ensure_string(shell["funcscmd"])
)
if "sourcer" in shell_keys:
shell["sourcer"] = (
None if shell["sourcer"] is None else ensure_string(shell["sourcer"])
)
if "seterrprevcmd" in shell_keys:
shell["seterrprevcmd"] = (
None
if shell["seterrprevcmd"] is None
else ensure_string(shell["seterrprevcmd"])
)
if "seterrpostcmd" in shell_keys:
shell["seterrpostcmd"] = (
None
if shell["seterrpostcmd"] is None
else ensure_string(shell["seterrpostcmd"])
)
return shell
开发者ID:ericmharris,项目名称:xonsh,代码行数:59,代码来源:foreign_shells.py
示例3: make_xontrib
def make_xontrib(xontrib, package):
"""Makes a message and StoreNonEmpty node for a xontrib."""
name = xontrib.get('name', '<unknown-xontrib-name>')
msg = '\n{BOLD_CYAN}' + name + '{NO_COLOR}\n'
if 'url' in xontrib:
msg += '{RED}url:{NO_COLOR} ' + xontrib['url'] + '\n'
if 'package' in xontrib:
msg += '{RED}package:{NO_COLOR} ' + xontrib['package'] + '\n'
if 'url' in package:
if 'url' in xontrib and package['url'] != xontrib['url']:
msg += '{RED}package-url:{NO_COLOR} ' + package['url'] + '\n'
if 'license' in package:
msg += '{RED}license:{NO_COLOR} ' + package['license'] + '\n'
msg += '{PURPLE}installed?{NO_COLOR} '
msg += ('no' if find_xontrib(name) is None else 'yes') + '\n'
desc = xontrib.get('description', '')
if not isinstance(desc, str):
desc = ''.join(desc)
msg += _wrap_paragraphs(desc, width=69)
if msg.endswith('\n'):
msg = msg[:-1]
mnode = wiz.Message(message=msg)
convert = lambda x: name if to_bool(x) else wiz.Unstorable
pnode = wiz.StoreNonEmpty(XONTRIB_PROMPT, converter=convert,
path=_xontrib_path)
return mnode, pnode
开发者ID:Siecje,项目名称:xonsh,代码行数:26,代码来源:xonfig.py
示例4: make_xontrib
def make_xontrib(xontrib, package):
"""Makes a message and StoreNonEmpty node for a xontrib."""
name = xontrib.get("name", "<unknown-xontrib-name>")
msg = "\n{BOLD_CYAN}" + name + "{NO_COLOR}\n"
if "url" in xontrib:
msg += "{RED}url:{NO_COLOR} " + xontrib["url"] + "\n"
if "package" in xontrib:
msg += "{RED}package:{NO_COLOR} " + xontrib["package"] + "\n"
if "url" in package:
if "url" in xontrib and package["url"] != xontrib["url"]:
msg += "{RED}package-url:{NO_COLOR} " + package["url"] + "\n"
if "license" in package:
msg += "{RED}license:{NO_COLOR} " + package["license"] + "\n"
msg += "{PURPLE}installed?{NO_COLOR} "
msg += ("no" if find_xontrib(name) is None else "yes") + "\n"
desc = xontrib.get("description", "")
if not isinstance(desc, str):
desc = "".join(desc)
msg += _wrap_paragraphs(desc, width=69)
if msg.endswith("\n"):
msg = msg[:-1]
mnode = wiz.Message(message=msg)
convert = lambda x: name if to_bool(x) else wiz.Unstorable
pnode = wiz.StoreNonEmpty(XONTRIB_PROMPT, converter=convert, path=_xontrib_path)
return mnode, pnode
开发者ID:Carreau,项目名称:xonsh,代码行数:25,代码来源:xonfig.py
示例5: _querycompletions
def _querycompletions(self, completions, loc):
"""Returns whether or not we should show completions"""
if os.path.commonprefix([c[loc:] for c in completions]):
return True
elif len(completions) <= builtins.__xonsh_env__.get('COMPLETION_QUERY_LIMIT'):
return True
msg = '\nDisplay all {} possibilities? '.format(len(completions))
msg += '({GREEN}y{NO_COLOR} or {RED}n{NO_COLOR})'
self.print_color(msg, end='', flush=True, file=sys.stderr)
yn = 'x'
while yn not in 'yn':
yn = sys.stdin.read(1)
show_completions = to_bool(yn)
print()
if not show_completions:
rl_on_new_line()
return False
w, h = shutil.get_terminal_size()
lines = columnize(completions, width=w)
more_msg = self.format_color('{YELLOW}==={NO_COLOR} more or '
'{PURPLE}({NO_COLOR}q{PURPLE}){NO_COLOR}uit '
'{YELLOW}==={NO_COLOR}')
while len(lines) > h - 1:
print(''.join(lines[:h-1]), end='', flush=True, file=sys.stderr)
lines = lines[h-1:]
print(more_msg, end='', flush=True, file=sys.stderr)
q = sys.stdin.read(1).lower()
print(flush=True, file=sys.stderr)
if q == 'q':
rl_on_new_line()
return False
print(''.join(lines), end='', flush=True, file=sys.stderr)
rl_on_new_line()
return False
开发者ID:tinloaf,项目名称:xonsh,代码行数:34,代码来源:readline_shell.py
示例6: test_to_bool
def test_to_bool():
cases = [
(True, True),
(False, False),
(None, False),
('', False),
('0', False),
('False', False),
('NONE', False),
('TRUE', True),
('1', True),
(0, False),
(1, True),
]
for inp, exp in cases:
obs = to_bool(inp)
yield assert_equal, exp, obs
开发者ID:gforsyth,项目名称:xonsh,代码行数:17,代码来源:test_tools.py
示例7: _querycompletions
def _querycompletions(self, completions, loc):
"""Returns whether or not we should show completions. 0 means that prefixes
should not be shown, 1 means that there is a common prefix among all completions
and they should be shown, while 2 means that there is no common prefix but
we are under the query limit and they should be shown.
"""
if os.path.commonprefix([c[loc:] for c in completions]):
return 1
elif len(completions) <= builtins.__xonsh__.env.get("COMPLETION_QUERY_LIMIT"):
return 2
msg = "\nDisplay all {} possibilities? ".format(len(completions))
msg += "({GREEN}y{NO_COLOR} or {RED}n{NO_COLOR})"
self.print_color(msg, end="", flush=True, file=sys.stderr)
yn = "x"
while yn not in "yn":
yn = sys.stdin.read(1)
show_completions = to_bool(yn)
print()
if not show_completions:
rl_on_new_line()
return 0
w, h = shutil.get_terminal_size()
lines = columnize(completions, width=w)
more_msg = self.format_color(
"{YELLOW}==={NO_COLOR} more or "
"{PURPLE}({NO_COLOR}q{PURPLE}){NO_COLOR}uit "
"{YELLOW}==={NO_COLOR}"
)
while len(lines) > h - 1:
print("".join(lines[: h - 1]), end="", flush=True, file=sys.stderr)
lines = lines[h - 1 :]
print(more_msg, end="", flush=True, file=sys.stderr)
q = sys.stdin.read(1).lower()
print(flush=True, file=sys.stderr)
if q == "q":
rl_on_new_line()
return 0
print("".join(lines), end="", flush=True, file=sys.stderr)
rl_on_new_line()
return 0
开发者ID:donnemartin,项目名称:gitsome,代码行数:40,代码来源:readline_shell.py
示例8: test_to_bool
def test_to_bool(inp, exp):
obs = to_bool(inp)
assert exp == obs
开发者ID:mitnk,项目名称:xonsh,代码行数:3,代码来源:test_tools.py
注:本文中的xonsh.tools.to_bool函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论