Update of /cvsroot/jython/jython/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv10847
Modified Files:
getopt.py
Log Message:
Updated to use CPython 2.1a1
Index: getopt.py
===================================================================
RCS file: /cvsroot/jython/jython/Lib/getopt.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** getopt.py 2000/11/17 20:46:17 1.2
--- getopt.py 2001/01/31 10:36:14 1.3
***************
*** 18,31 ****
# to class-based exceptions.
class GetoptError(Exception):
opt = ''
msg = ''
! def __init__(self, *args):
! self.args = args
! if len(args) == 1:
! self.msg = args[0]
! elif len(args) == 2:
! self.msg = args[0]
! self.opt = args[1]
def __str__(self):
--- 18,30 ----
# to class-based exceptions.
+ __all__ = ["GetoptError","error","getopt"]
+
class GetoptError(Exception):
opt = ''
msg = ''
! def __init__(self, msg, opt):
! self.msg = msg
! self.opt = opt
! Exception.__init__(self, msg, opt)
def __str__(self):
***************
*** 66,71 ****
else:
longopts = list(longopts)
! longopts.sort()
! while args and args[0][:1] == '-' and args[0] != '-':
if args[0] == '--':
args = args[1:]
--- 65,69 ----
else:
longopts = list(longopts)
! while args and args[0].startswith('-') and args[0] != '-':
if args[0] == '--':
args = args[1:]
***************
*** 81,87 ****
try:
i = opt.index('=')
- opt, optarg = opt[:i], opt[i+1:]
except ValueError:
optarg = None
has_arg, opt = long_has_args(opt, longopts)
--- 79,86 ----
try:
i = opt.index('=')
except ValueError:
optarg = None
+ else:
+ opt, optarg = opt[:i], opt[i+1:]
has_arg, opt = long_has_args(opt, longopts)
***************
*** 100,115 ****
# full option name
def long_has_args(opt, longopts):
! optlen = len(opt)
! for i in range(len(longopts)):
! x, y = longopts[i][:optlen], longopts[i][optlen:]
! if opt != x:
! continue
! if y != '' and y != '=' and i+1 < len(longopts):
! if opt == longopts[i+1][:optlen]:
! raise GetoptError('option --%s not a unique prefix' % opt, opt)
! if longopts[i][-1:] in ('=', ):
! return 1, longopts[i][:-1]
! return 0, longopts[i]
! raise GetoptError('option --%s not recognized' % opt, opt)
def do_shorts(opts, optstring, shortopts, args):
--- 99,121 ----
# full option name
def long_has_args(opt, longopts):
! possibilities = [o for o in longopts if o.startswith(opt)]
! if not possibilities:
! raise GetoptError('option --%s not recognized' % opt, opt)
! # Is there an exact match?
! if opt in possibilities:
! return 0, opt
! elif opt + '=' in possibilities:
! return 1, opt
! # No exact match, so better be unique.
! if len(possibilities) > 1:
! # XXX since possibilities contains all valid continuations, might be
! # nice to work them into the error msg
! raise GetoptError('option --%s not a unique prefix' % opt, opt)
! assert len(possibilities) == 1
! unique_match = possibilities[0]
! has_arg = unique_match.endswith('=')
! if has_arg:
! unique_match = unique_match[:-1]
! return has_arg, unique_match
def do_shorts(opts, optstring, shortopts, args):
|