Mercurial > hg
comparison hgext/mq.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 | cc3d94e5994e |
children | 0fdf2c304019 |
comparison
equal
deleted
inserted
replaced
25659:d60678a567a9 | 25660:328739ea70c3 |
---|---|
446 self.ui.warn(_('malformated mq status line: %s\n') % entry) | 446 self.ui.warn(_('malformated mq status line: %s\n') % entry) |
447 # else we ignore empty lines | 447 # else we ignore empty lines |
448 try: | 448 try: |
449 lines = self.opener.read(self.statuspath).splitlines() | 449 lines = self.opener.read(self.statuspath).splitlines() |
450 return list(parselines(lines)) | 450 return list(parselines(lines)) |
451 except IOError, e: | 451 except IOError as e: |
452 if e.errno == errno.ENOENT: | 452 if e.errno == errno.ENOENT: |
453 return [] | 453 return [] |
454 raise | 454 raise |
455 | 455 |
456 @util.propertycache | 456 @util.propertycache |
457 def fullseries(self): | 457 def fullseries(self): |
458 try: | 458 try: |
459 return self.opener.read(self.seriespath).splitlines() | 459 return self.opener.read(self.seriespath).splitlines() |
460 except IOError, e: | 460 except IOError as e: |
461 if e.errno == errno.ENOENT: | 461 if e.errno == errno.ENOENT: |
462 return [] | 462 return [] |
463 raise | 463 raise |
464 | 464 |
465 @util.propertycache | 465 @util.propertycache |
572 def active(self): | 572 def active(self): |
573 if self.activeguards is None: | 573 if self.activeguards is None: |
574 self.activeguards = [] | 574 self.activeguards = [] |
575 try: | 575 try: |
576 guards = self.opener.read(self.guardspath).split() | 576 guards = self.opener.read(self.guardspath).split() |
577 except IOError, err: | 577 except IOError as err: |
578 if err.errno != errno.ENOENT: | 578 if err.errno != errno.ENOENT: |
579 raise | 579 raise |
580 guards = [] | 580 guards = [] |
581 for i, guard in enumerate(guards): | 581 for i, guard in enumerate(guards): |
582 bad = self.checkguard(guard) | 582 bad = self.checkguard(guard) |
673 undo = repo.sjoin('undo') | 673 undo = repo.sjoin('undo') |
674 if not os.path.exists(undo): | 674 if not os.path.exists(undo): |
675 return | 675 return |
676 try: | 676 try: |
677 os.unlink(undo) | 677 os.unlink(undo) |
678 except OSError, inst: | 678 except OSError as inst: |
679 self.ui.warn(_('error removing undo: %s\n') % str(inst)) | 679 self.ui.warn(_('error removing undo: %s\n') % str(inst)) |
680 | 680 |
681 def backup(self, repo, files, copy=False): | 681 def backup(self, repo, files, copy=False): |
682 # backup local changes in --force case | 682 # backup local changes in --force case |
683 for f in sorted(files): | 683 for f in sorted(files): |
802 files = set() | 802 files = set() |
803 try: | 803 try: |
804 fuzz = patchmod.patch(self.ui, repo, patchfile, strip=1, | 804 fuzz = patchmod.patch(self.ui, repo, patchfile, strip=1, |
805 files=files, eolmode=None) | 805 files=files, eolmode=None) |
806 return (True, list(files), fuzz) | 806 return (True, list(files), fuzz) |
807 except Exception, inst: | 807 except Exception as inst: |
808 self.ui.note(str(inst) + '\n') | 808 self.ui.note(str(inst) + '\n') |
809 if not self.ui.verbose: | 809 if not self.ui.verbose: |
810 self.ui.warn(_("patch failed, unable to continue (try -v)\n")) | 810 self.ui.warn(_("patch failed, unable to continue (try -v)\n")) |
811 self.ui.traceback() | 811 self.ui.traceback() |
812 return (False, list(files), False) | 812 return (False, list(files), False) |
957 if r: | 957 if r: |
958 r[None].forget(patches) | 958 r[None].forget(patches) |
959 for p in patches: | 959 for p in patches: |
960 try: | 960 try: |
961 os.unlink(self.join(p)) | 961 os.unlink(self.join(p)) |
962 except OSError, inst: | 962 except OSError as inst: |
963 if inst.errno != errno.ENOENT: | 963 if inst.errno != errno.ENOENT: |
964 raise | 964 raise |
965 | 965 |
966 qfinished = [] | 966 qfinished = [] |
967 if numrevs: | 967 if numrevs: |
1157 wlock = repo.wlock() | 1157 wlock = repo.wlock() |
1158 try: | 1158 try: |
1159 try: | 1159 try: |
1160 # if patch file write fails, abort early | 1160 # if patch file write fails, abort early |
1161 p = self.opener(patchfn, "w") | 1161 p = self.opener(patchfn, "w") |
1162 except IOError, e: | 1162 except IOError as e: |
1163 raise util.Abort(_('cannot write patch "%s": %s') | 1163 raise util.Abort(_('cannot write patch "%s": %s') |
1164 % (patchfn, e.strerror)) | 1164 % (patchfn, e.strerror)) |
1165 try: | 1165 try: |
1166 defaultmsg = "[mq]: %s" % patchfn | 1166 defaultmsg = "[mq]: %s" % patchfn |
1167 editor = cmdutil.getcommiteditor(editform=editform) | 1167 editor = cmdutil.getcommiteditor(editform=editform) |
1814 def init(self, repo, create=False): | 1814 def init(self, repo, create=False): |
1815 if not create and os.path.isdir(self.path): | 1815 if not create and os.path.isdir(self.path): |
1816 raise util.Abort(_("patch queue directory already exists")) | 1816 raise util.Abort(_("patch queue directory already exists")) |
1817 try: | 1817 try: |
1818 os.mkdir(self.path) | 1818 os.mkdir(self.path) |
1819 except OSError, inst: | 1819 except OSError as inst: |
1820 if inst.errno != errno.EEXIST or not create: | 1820 if inst.errno != errno.EEXIST or not create: |
1821 raise | 1821 raise |
1822 if create: | 1822 if create: |
1823 return self.qrepo(create=True) | 1823 return self.qrepo(create=True) |
1824 | 1824 |