def test_argvquote(st, esc, forced): obs = argvquote(st) assert esc == obs if forced is None: forced = esc obs = argvquote(st, force=True) assert forced == obs
def test_argvquote(): cases = [('', '""'), ('foo', 'foo'), (r'arg1 "hallo, "world"" "\some\path with\spaces")', r'"arg1 \"hallo, \"world\"\" \"\some\path with\spaces\")"'), (r'"argument"2" argument3 argument4', r'"\"argument\"2\" argument3 argument4"'), (r'"\foo\bar bar\foo\" arg', r'"\"\foo\bar bar\foo\\\" arg"')] for st, esc in cases: obs = argvquote(st) yield assert_equal, esc, obs
def test_argvquote(): cases = [ ('', '""'), ('foo', 'foo'), (r'arg1 "hallo, "world"" "\some\path with\spaces")', r'"arg1 \"hallo, \"world\"\" \"\some\path with\spaces\")"'), (r'"argument"2" argument3 argument4', r'"\"argument\"2\" argument3 argument4"'), (r'"\foo\bar bar\foo\" arg', r'"\"\foo\bar bar\foo\\\" arg"') ] for st, esc in cases: obs = argvquote(st) yield assert_equal, esc, obs
def source_cmd(args, stdin=None): """Simple cmd.exe-specific wrapper around source-foreign.""" args = list(args) fpath = locate_binary(args[0]) args[0] = fpath if fpath else args[0] if not os.path.isfile(args[0]): return (None, 'xonsh: error: File not found: {}\n'.format(args[0]), 1) prevcmd = 'call ' prevcmd += ' '.join([argvquote(arg, force=True) for arg in args]) prevcmd = escape_windows_cmd_string(prevcmd) args.append('--prevcmd={}'.format(prevcmd)) args.insert(0, 'cmd') args.append('--interactive=0') args.append('--sourcer=call') args.append('--envcmd=set') args.append('--seterrpostcmd=if errorlevel 1 exit 1') args.append('--use-tmpfile=1') return source_foreign(args, stdin=stdin)
def source_cmd(args, stdin=None): """Simple cmd.exe-specific wrapper around source-foreign.""" args = list(args) fpath = locate_binary(args[0]) args[0] = fpath if fpath else args[0] if not os.path.isfile(args[0]): return (None, "xonsh: error: File not found: {}\n".format(args[0]), 1) prevcmd = "call " prevcmd += " ".join([argvquote(arg, force=True) for arg in args]) prevcmd = escape_windows_cmd_string(prevcmd) args.append("--prevcmd={}".format(prevcmd)) args.insert(0, "cmd") args.append("--interactive=0") args.append("--sourcer=call") args.append("--envcmd=set") args.append("--seterrpostcmd=if errorlevel 1 exit 1") args.append("--use-tmpfile=1") with builtins.__xonsh_env__.swap(PROMPT="$P$G"): return source_foreign(args, stdin=stdin)
def source_cmd(args, stdin=None): """Simple cmd.exe-specific wrapper around source-foreign.""" args = list(args) fpath = locate_binary(args[0]) args[0] = fpath if fpath else args[0] if not os.path.isfile(args[0]): return (None, "xonsh: error: File not found: {}\n".format(args[0]), 1) prevcmd = "call " prevcmd += " ".join([argvquote(arg, force=True) for arg in args]) prevcmd = escape_windows_cmd_string(prevcmd) args.append("--prevcmd={}".format(prevcmd)) args.insert(0, "cmd") args.append("--interactive=0") args.append("--sourcer=call") args.append("--envcmd=set") args.append("--seterrpostcmd=if errorlevel 1 exit 1") args.append("--use-tmpfile=1") with builtins.__xonsh__.env.swap(PROMPT="$P$G"): return source_foreign(args, stdin=stdin)
def source_cmd_fn( files: Annotated[tp.List[str], Arg(nargs="+")], login=False, aliascmd=None, extra_args="", safe=True, postcmd="", funcscmd="", seterrprevcmd=None, overwrite_aliases=False, suppress_skip_message=False, show=False, dryrun=False, _stderr=None, ): """ Source cmd.exe files Parameters ---------- files paths to source files. login : -l, --login whether the sourced shell should be login envcmd : --envcmd command to print environment aliascmd : --aliascmd command to print aliases extra_args : --extra-args extra arguments needed to run the shell safe : -s, --safe whether the source shell should be run safely, and not raise any errors, even if they occur. postcmd : --postcmd command(s) to run after all other commands funcscmd : --funcscmd code to find locations of all native functions in the shell language. seterrprevcmd : --seterrprevcmd command(s) to set exit-on-error before any other commands. overwrite_aliases : --overwrite-aliases flag for whether or not sourced aliases should replace the current xonsh aliases. suppress_skip_message : --suppress-skip-message flag for whether or not skip messages should be suppressed. show : --show show the script output. dryrun : -d, --dry-run Will not actually source the file. """ args = list(files) fpath = locate_binary(args[0]) args[0] = fpath if fpath else args[0] if not os.path.isfile(args[0]): return (None, f"xonsh: error: File not found: {args[0]}\n", 1) prevcmd = "call " prevcmd += " ".join([argvquote(arg, force=True) for arg in args]) prevcmd = escape_windows_cmd_string(prevcmd) with XSH.env.swap(PROMPT="$P$G"): return source_foreign_fn( shell="cmd", files_or_code=args, interactive=True, sourcer="call", envcmd="set", seterrpostcmd="if errorlevel 1 exit 1", use_tmpfile=True, prevcmd=prevcmd, # from this function login=login, aliascmd=aliascmd, extra_args=extra_args, safe=safe, postcmd=postcmd, funcscmd=funcscmd, seterrprevcmd=seterrprevcmd, overwrite_aliases=overwrite_aliases, suppress_skip_message=suppress_skip_message, show=show, dryrun=dryrun, )
def test_argvquote(st, esc): obs = argvquote(st) assert esc == obs