mirror of https://github.com/python/cpython
Better detection of bad entries in option table.
Better error messages for bad entries in option table.
This commit is contained in:
parent
8c66b697c1
commit
0081cc529c
|
@ -47,16 +47,24 @@ def fancy_getopt (options, object, args):
|
||||||
attr_name = {}
|
attr_name = {}
|
||||||
takes_arg = {}
|
takes_arg = {}
|
||||||
|
|
||||||
for (long, short, help) in options:
|
for option in options:
|
||||||
|
try:
|
||||||
|
(long, short, help) = option
|
||||||
|
except ValueError:
|
||||||
|
raise DistutilsGetoptError, \
|
||||||
|
"invalid option tuple " + str (option)
|
||||||
|
|
||||||
# Type-check the option names
|
# Type-check the option names
|
||||||
if type (long) is not StringType or len (long) < 2:
|
if type (long) is not StringType or len (long) < 2:
|
||||||
raise DistutilsGetoptError, \
|
raise DistutilsGetoptError, \
|
||||||
"long option must be a string of length >= 2"
|
"long option '%s' must be a string of length >= 2" % \
|
||||||
|
long
|
||||||
|
|
||||||
if (not ((short is None) or
|
if (not ((short is None) or
|
||||||
(type (short) is StringType and len (short) == 1))):
|
(type (short) is StringType and len (short) == 1))):
|
||||||
raise DistutilsGetoptError, \
|
raise DistutilsGetoptError, \
|
||||||
"short option must be None or string of length 1"
|
"short option '%s' must be None or string of length 1" % \
|
||||||
|
short
|
||||||
|
|
||||||
long_opts.append (long)
|
long_opts.append (long)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue