diff -r b26db63bb931 Lib/getopt.py --- a/Lib/getopt.py Thu Jan 23 00:36:46 2014 -0500 +++ b/Lib/getopt.py Fri Jan 31 23:08:21 2014 +0800 @@ -147,21 +147,19 @@ return opts, prog_args def do_longs(opts, opt, longopts, args): - try: - i = opt.index('=') - except ValueError: - optarg = None - else: - opt, optarg = opt[:i], opt[i+1:] + head, sep, optarg = opt.partition('=') + if sep: + opt = head has_arg, opt = long_has_args(opt, longopts) if has_arg: - if optarg is None: + if not sep: if not args: - raise GetoptError(_('option --%s requires argument') % opt, opt) + raise GetoptError('option --%s requires argument' % opt, opt) optarg, args = args[0], args[1:] - elif optarg is not None: - raise GetoptError(_('option --%s must not have an argument') % opt, opt) + elif sep: + opt = head + raise GetoptError('option --%s must not have an argument' % opt, opt) opts.append(('--' + opt, optarg or '')) return opts, args @@ -205,10 +203,10 @@ return opts, args def short_has_arg(opt, shortopts): - for i in range(len(shortopts)): - if opt == shortopts[i] != ':': - return shortopts.startswith(':', i+1) - raise GetoptError(_('option -%s not recognized') % opt, opt) + for index, shortopt in enumerate(shortopts): + if opt == shortopt != ':': + return shortopts.startswith(':', index+1) + raise GetoptError('option -%s not recognized' % opt, opt) if __name__ == '__main__': import sys