MCPcopy
hub / github.com/tanelpoder/0xtools / _read_args_from_files

Method _read_args_from_files

lib/0xtools/argparse.py:1997–2024  ·  view source on GitHub ↗
(self, arg_strings)

Source from the content-addressed store, hash-verified

1995 return namespace, extras
1996
1997 def _read_args_from_files(self, arg_strings):
1998 # expand arguments referencing files
1999 new_arg_strings = []
2000 for arg_string in arg_strings:
2001
2002 # for regular arguments, just add them back into the list
2003 if not arg_string or arg_string[0] not in self.fromfile_prefix_chars:
2004 new_arg_strings.append(arg_string)
2005
2006 # replace arguments referencing files with the file content
2007 else:
2008 try:
2009 args_file = open(arg_string[1:])
2010 try:
2011 arg_strings = []
2012 for arg_line in args_file.read().splitlines():
2013 for arg in self.convert_arg_line_to_args(arg_line):
2014 arg_strings.append(arg)
2015 arg_strings = self._read_args_from_files(arg_strings)
2016 new_arg_strings.extend(arg_strings)
2017 finally:
2018 args_file.close()
2019 except IOError:
2020 err = _sys.exc_info()[1]
2021 self.error(str(err))
2022
2023 # return the modified argument list
2024 return new_arg_strings
2025
2026 def convert_arg_line_to_args(self, arg_line):
2027 return [arg_line]

Callers 1

_parse_known_argsMethod · 0.95

Calls 3

errorMethod · 0.95
closeMethod · 0.80

Tested by

no test coverage detected