Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 25660:328739ea70c3
global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".
This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.
This patch was produced by running `2to3 -f except -w -n .`.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 23 Jun 2015 22:20:08 -0700 |
parents | e93036747902 |
children | 3b1fc40626d8 |
comparison
equal
deleted
inserted
replaced
25659:d60678a567a9 | 25660:328739ea70c3 |
---|---|
2338 | 2338 |
2339 # encoding | 2339 # encoding |
2340 ui.status(_("checking encoding (%s)...\n") % encoding.encoding) | 2340 ui.status(_("checking encoding (%s)...\n") % encoding.encoding) |
2341 try: | 2341 try: |
2342 encoding.fromlocal("test") | 2342 encoding.fromlocal("test") |
2343 except util.Abort, inst: | 2343 except util.Abort as inst: |
2344 ui.write(" %s\n" % inst) | 2344 ui.write(" %s\n" % inst) |
2345 ui.write(_(" (check that your locale is properly set)\n")) | 2345 ui.write(_(" (check that your locale is properly set)\n")) |
2346 problems += 1 | 2346 problems += 1 |
2347 | 2347 |
2348 # Python | 2348 # Python |
2356 ui.status(_("checking installed modules (%s)...\n") | 2356 ui.status(_("checking installed modules (%s)...\n") |
2357 % os.path.dirname(__file__)) | 2357 % os.path.dirname(__file__)) |
2358 try: | 2358 try: |
2359 import bdiff, mpatch, base85, osutil | 2359 import bdiff, mpatch, base85, osutil |
2360 dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes | 2360 dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes |
2361 except Exception, inst: | 2361 except Exception as inst: |
2362 ui.write(" %s\n" % inst) | 2362 ui.write(" %s\n" % inst) |
2363 ui.write(_(" One or more extensions could not be found")) | 2363 ui.write(_(" One or more extensions could not be found")) |
2364 ui.write(_(" (check that you compiled the extensions)\n")) | 2364 ui.write(_(" (check that you compiled the extensions)\n")) |
2365 problems += 1 | 2365 problems += 1 |
2366 | 2366 |
2372 m = templater.templatepath("map-cmdline.default") | 2372 m = templater.templatepath("map-cmdline.default") |
2373 if m: | 2373 if m: |
2374 # template found, check if it is working | 2374 # template found, check if it is working |
2375 try: | 2375 try: |
2376 templater.templater(m) | 2376 templater.templater(m) |
2377 except Exception, inst: | 2377 except Exception as inst: |
2378 ui.write(" %s\n" % inst) | 2378 ui.write(" %s\n" % inst) |
2379 p = None | 2379 p = None |
2380 else: | 2380 else: |
2381 ui.write(_(" template 'default' not found\n")) | 2381 ui.write(_(" template 'default' not found\n")) |
2382 p = None | 2382 p = None |
2404 | 2404 |
2405 # check username | 2405 # check username |
2406 ui.status(_("checking username...\n")) | 2406 ui.status(_("checking username...\n")) |
2407 try: | 2407 try: |
2408 ui.username() | 2408 ui.username() |
2409 except util.Abort, e: | 2409 except util.Abort as e: |
2410 ui.write(" %s\n" % e) | 2410 ui.write(" %s\n" % e) |
2411 ui.write(_(" (specify a username in your configuration file)\n")) | 2411 ui.write(_(" (specify a username in your configuration file)\n")) |
2412 problems += 1 | 2412 problems += 1 |
2413 | 2413 |
2414 if not problems: | 2414 if not problems: |
2515 else: | 2515 else: |
2516 locker = 'user %s, process %s, host %s' \ | 2516 locker = 'user %s, process %s, host %s' \ |
2517 % (user, pid, host) | 2517 % (user, pid, host) |
2518 ui.write("%-6s %s (%ds)\n" % (name + ":", locker, age)) | 2518 ui.write("%-6s %s (%ds)\n" % (name + ":", locker, age)) |
2519 return 1 | 2519 return 1 |
2520 except OSError, e: | 2520 except OSError as e: |
2521 if e.errno != errno.ENOENT: | 2521 if e.errno != errno.ENOENT: |
2522 raise | 2522 raise |
2523 | 2523 |
2524 ui.write("%-6s free\n" % (name + ":")) | 2524 ui.write("%-6s free\n" % (name + ":")) |
2525 return 0 | 2525 return 0 |
2579 parents = tuple(p.node() for p in parents) | 2579 parents = tuple(p.node() for p in parents) |
2580 repo.obsstore.create(tr, prec, succs, opts['flags'], | 2580 repo.obsstore.create(tr, prec, succs, opts['flags'], |
2581 parents=parents, date=date, | 2581 parents=parents, date=date, |
2582 metadata=metadata) | 2582 metadata=metadata) |
2583 tr.close() | 2583 tr.close() |
2584 except ValueError, exc: | 2584 except ValueError as exc: |
2585 raise util.Abort(_('bad obsmarker input: %s') % exc) | 2585 raise util.Abort(_('bad obsmarker input: %s') % exc) |
2586 finally: | 2586 finally: |
2587 tr.release() | 2587 tr.release() |
2588 finally: | 2588 finally: |
2589 l.release() | 2589 l.release() |
3468 raise util.Abort(_("can't specify --continue and revisions")) | 3468 raise util.Abort(_("can't specify --continue and revisions")) |
3469 # read in unfinished revisions | 3469 # read in unfinished revisions |
3470 try: | 3470 try: |
3471 nodes = repo.vfs.read('graftstate').splitlines() | 3471 nodes = repo.vfs.read('graftstate').splitlines() |
3472 revs = [repo[node].rev() for node in nodes] | 3472 revs = [repo[node].rev() for node in nodes] |
3473 except IOError, inst: | 3473 except IOError as inst: |
3474 if inst.errno != errno.ENOENT: | 3474 if inst.errno != errno.ENOENT: |
3475 raise | 3475 raise |
3476 raise util.Abort(_("no graft state found, can't continue")) | 3476 raise util.Abort(_("no graft state found, can't continue")) |
3477 else: | 3477 else: |
3478 cmdutil.checkunfinished(repo) | 3478 cmdutil.checkunfinished(repo) |
3662 reflags = re.M | 3662 reflags = re.M |
3663 if opts.get('ignore_case'): | 3663 if opts.get('ignore_case'): |
3664 reflags |= re.I | 3664 reflags |= re.I |
3665 try: | 3665 try: |
3666 regexp = util.re.compile(pattern, reflags) | 3666 regexp = util.re.compile(pattern, reflags) |
3667 except re.error, inst: | 3667 except re.error as inst: |
3668 ui.warn(_("grep: invalid match pattern: %s\n") % inst) | 3668 ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
3669 return 1 | 3669 return 1 |
3670 sep, eol = ':', '\n' | 3670 sep, eol = ':', '\n' |
3671 if opts.get('print0'): | 3671 if opts.get('print0'): |
3672 sep = eol = '\0' | 3672 sep = eol = '\0' |
5081 return | 5081 return |
5082 if optupdate: | 5082 if optupdate: |
5083 checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout) | 5083 checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout) |
5084 try: | 5084 try: |
5085 ret = hg.update(repo, checkout) | 5085 ret = hg.update(repo, checkout) |
5086 except util.Abort, inst: | 5086 except util.Abort as inst: |
5087 ui.warn(_("not updating: %s\n") % str(inst)) | 5087 ui.warn(_("not updating: %s\n") % str(inst)) |
5088 if inst.hint: | 5088 if inst.hint: |
5089 ui.warn(_("(%s)\n") % inst.hint) | 5089 ui.warn(_("(%s)\n") % inst.hint) |
5090 return 0 | 5090 return 0 |
5091 if not ret and not checkout: | 5091 if not ret and not checkout: |