MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _check_cmd

Function _check_cmd

tools/python-3.11.9-amd64/Lib/_bootsubprocess.py:36–62  ·  view source on GitHub ↗
(cmd)

Source from the content-addressed store, hash-verified

34
35
36def _check_cmd(cmd):
37 # Use regex [a-zA-Z0-9./-]+: reject empty string, space, etc.
38 safe_chars = []
39 for first, last in (("a", "z"), ("A", "Z"), ("0", "9")):
40 for ch in range(ord(first), ord(last) + 1):
41 safe_chars.append(chr(ch))
42 safe_chars.append("./-")
43 safe_chars = ''.join(safe_chars)
44
45 if isinstance(cmd, (tuple, list)):
46 check_strs = cmd
47 elif isinstance(cmd, str):
48 check_strs = [cmd]
49 else:
50 return False
51
52 for arg in check_strs:
53 if not isinstance(arg, str):
54 return False
55 if not arg:
56 # reject empty string
57 return False
58 for ch in arg:
59 if ch not in safe_chars:
60 return False
61
62 return True
63
64
65# _aix_support used by distutil.util calls subprocess.check_output()

Callers 1

check_outputFunction · 0.85

Calls 2

appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected