MCPcopy Index your code
hub / github.com/python/cpython / _read_args_from_files

Method _read_args_from_files

Lib/argparse.py:2442–2467  ·  view source on GitHub ↗
(self, arg_strings)

Source from the content-addressed store, hash-verified

2440 return namespace, extras
2441
2442 def _read_args_from_files(self, arg_strings):
2443 # expand arguments referencing files
2444 new_arg_strings = []
2445 for arg_string in arg_strings:
2446
2447 # for regular arguments, just add them back into the list
2448 if not arg_string or arg_string[0] not in self.fromfile_prefix_chars:
2449 new_arg_strings.append(arg_string)
2450
2451 # replace arguments referencing files with the file content
2452 else:
2453 try:
2454 with open(arg_string[1:],
2455 encoding=_sys.getfilesystemencoding(),
2456 errors=_sys.getfilesystemencodeerrors()) as args_file:
2457 arg_strings = []
2458 for arg_line in args_file.read().splitlines():
2459 for arg in self.convert_arg_line_to_args(arg_line):
2460 arg_strings.append(arg)
2461 arg_strings = self._read_args_from_files(arg_strings)
2462 new_arg_strings.extend(arg_strings)
2463 except OSError as err:
2464 raise ArgumentError(None, str(err))
2465
2466 # return the modified argument list
2467 return new_arg_strings
2468
2469 def convert_arg_line_to_args(self, arg_line):
2470 return [arg_line]

Callers 1

_parse_known_argsMethod · 0.95

Calls 8

strFunction · 0.85
openFunction · 0.70
ArgumentErrorClass · 0.70
appendMethod · 0.45
splitlinesMethod · 0.45
readMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected