[issue10523] argparse has problem parsing option files containing empty rows

2010-11-24 Thread Michal Pomorski

New submission from Michal Pomorski :

When using the argument file option, i.e  @file_with_arguments the following 
problems arise:

1. argparse crashes when the file contains an empty line (even if it is the 
last line) - arg_string[0] is done when arg_string is empty. 
This is caused by the use of splitlines() instead of strip().split() in the 
function _read_args_from_files(self, arg_strings)

2. options separated by spaces in one row are passed as a single long option, 
meaning each option has to be on its own line.
This is caused by the new function 
   def convert_arg_line_to_args(self, arg_line):
return [arg_line]
   which should be 
return arg_line.split()


Both problems are caused by a modification in
def _read_args_from_files(self, arg_strings)
The version from argparse 1.0.1 worked well and was correct, it should be 
sufficient to reverse the changes done from 1.0.1 to 1.1.

Here is the old implementation:

def _read_args_from_files(self, arg_strings):
# expand arguments referencing files
new_arg_strings = []
for arg_string in arg_strings:

# for regular arguments, just add them back into the list
if arg_string[0] not in self.fromfile_prefix_chars:
new_arg_strings.append(arg_string)

# replace arguments referencing files with the file content
else:
try:
args_file = open(arg_string[1:])
try:
arg_strings = args_file.read().strip().split()
arg_strings = self._read_args_from_files(arg_strings)

new_arg_strings.extend(arg_strings)
finally:
args_file.close()
except IOError:
err = _sys.exc_info()[1]
self.error(str(err))

# return the modified argument list
return new_arg_strings

--
components: Library (Lib)
messages: 122314
nosy: Michal.Pomorski
priority: normal
severity: normal
status: open
title: argparse has problem parsing option files containing empty rows
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue10523>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10523] argparse has problem parsing option files containing empty rows

2010-11-24 Thread Michal Pomorski

Changes by Michal Pomorski :


--
type:  -> crash

___
Python tracker 
<http://bugs.python.org/issue10523>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com