summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 57eaaad..5fd82da 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1121,7 +1121,7 @@ class FileType(object):
the builtin open() function.
"""
- def __init__(self, mode='r', bufsize=None):
+ def __init__(self, mode='r', bufsize=-1):
self._mode = mode
self._bufsize = bufsize
@@ -1137,14 +1137,15 @@ class FileType(object):
raise ValueError(msg)
# all other arguments are used as file names
- if self._bufsize:
+ try:
return open(string, self._mode, self._bufsize)
- else:
- return open(string, self._mode)
+ except IOError as e:
+ message = _("can't open '%s': %s")
+ raise ArgumentTypeError(message % (string, e))
def __repr__(self):
- args = [self._mode, self._bufsize]
- args_str = ', '.join([repr(arg) for arg in args if arg is not None])
+ args = self._mode, self._bufsize
+ args_str = ', '.join(repr(arg) for arg in args if arg != -1)
return '%s(%s)' % (type(self).__name__, args_str)
# ===========================