Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/extensions.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 | de23a552fc23 |
children | 5e0d80195a0f |
comparison
equal
deleted
inserted
replaced
25659:d60678a567a9 | 25660:328739ea70c3 |
---|---|
51 fd, fpath, desc = imp.find_module(f, [d]) | 51 fd, fpath, desc = imp.find_module(f, [d]) |
52 return imp.load_module(module_name, fd, fpath, desc) | 52 return imp.load_module(module_name, fd, fpath, desc) |
53 else: | 53 else: |
54 try: | 54 try: |
55 return imp.load_source(module_name, path) | 55 return imp.load_source(module_name, path) |
56 except IOError, exc: | 56 except IOError as exc: |
57 if not exc.filename: | 57 if not exc.filename: |
58 exc.filename = path # python does not fill this | 58 exc.filename = path # python does not fill this |
59 raise | 59 raise |
60 | 60 |
61 def load(ui, name, path): | 61 def load(ui, name, path): |
80 for comp in components[1:]: | 80 for comp in components[1:]: |
81 mod = getattr(mod, comp) | 81 mod = getattr(mod, comp) |
82 return mod | 82 return mod |
83 try: | 83 try: |
84 mod = importh("hgext.%s" % name) | 84 mod = importh("hgext.%s" % name) |
85 except ImportError, err: | 85 except ImportError as err: |
86 ui.debug('could not import hgext.%s (%s): trying %s\n' | 86 ui.debug('could not import hgext.%s (%s): trying %s\n' |
87 % (name, err, name)) | 87 % (name, err, name)) |
88 if ui.debugflag: | 88 if ui.debugflag: |
89 ui.traceback() | 89 ui.traceback() |
90 mod = importh(name) | 90 mod = importh(name) |
103 continue | 103 continue |
104 try: | 104 try: |
105 load(ui, name, path) | 105 load(ui, name, path) |
106 except KeyboardInterrupt: | 106 except KeyboardInterrupt: |
107 raise | 107 raise |
108 except Exception, inst: | 108 except Exception as inst: |
109 if path: | 109 if path: |
110 ui.warn(_("*** failed to import extension %s from %s: %s\n") | 110 ui.warn(_("*** failed to import extension %s from %s: %s\n") |
111 % (name, path, inst)) | 111 % (name, path, inst)) |
112 else: | 112 else: |
113 ui.warn(_("*** failed to import extension %s: %s\n") | 113 ui.warn(_("*** failed to import extension %s: %s\n") |