Mercurial > hg
comparison mercurial/scmutil.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 | 3dabc9b7494a |
comparison
equal
deleted
inserted
replaced
25659:d60678a567a9 | 25660:328739ea70c3 |
---|---|
220 | 220 |
221 def tryread(self, path): | 221 def tryread(self, path): |
222 '''gracefully return an empty string for missing files''' | 222 '''gracefully return an empty string for missing files''' |
223 try: | 223 try: |
224 return self.read(path) | 224 return self.read(path) |
225 except IOError, inst: | 225 except IOError as inst: |
226 if inst.errno != errno.ENOENT: | 226 if inst.errno != errno.ENOENT: |
227 raise | 227 raise |
228 return "" | 228 return "" |
229 | 229 |
230 def tryreadlines(self, path, mode='rb'): | 230 def tryreadlines(self, path, mode='rb'): |
231 '''gracefully return an empty array for missing files''' | 231 '''gracefully return an empty array for missing files''' |
232 try: | 232 try: |
233 return self.readlines(path, mode=mode) | 233 return self.readlines(path, mode=mode) |
234 except IOError, inst: | 234 except IOError as inst: |
235 if inst.errno != errno.ENOENT: | 235 if inst.errno != errno.ENOENT: |
236 raise | 236 raise |
237 return [] | 237 return [] |
238 | 238 |
239 def open(self, path, mode="r", text=False, atomictemp=False, | 239 def open(self, path, mode="r", text=False, atomictemp=False, |
489 fd = util.posixfile(f) | 489 fd = util.posixfile(f) |
490 nlink = util.nlinks(f) | 490 nlink = util.nlinks(f) |
491 if nlink < 1: | 491 if nlink < 1: |
492 nlink = 2 # force mktempcopy (issue1922) | 492 nlink = 2 # force mktempcopy (issue1922) |
493 fd.close() | 493 fd.close() |
494 except (OSError, IOError), e: | 494 except (OSError, IOError) as e: |
495 if e.errno != errno.ENOENT: | 495 if e.errno != errno.ENOENT: |
496 raise | 496 raise |
497 nlink = 0 | 497 nlink = 0 |
498 util.ensuredirs(dirname, self.createmode, notindexed) | 498 util.ensuredirs(dirname, self.createmode, notindexed) |
499 if nlink > 0: | 499 if nlink > 0: |
517 util.ensuredirs(os.path.dirname(linkname), self.createmode) | 517 util.ensuredirs(os.path.dirname(linkname), self.createmode) |
518 | 518 |
519 if self._cansymlink: | 519 if self._cansymlink: |
520 try: | 520 try: |
521 os.symlink(src, linkname) | 521 os.symlink(src, linkname) |
522 except OSError, err: | 522 except OSError as err: |
523 raise OSError(err.errno, _('could not symlink to %r: %s') % | 523 raise OSError(err.errno, _('could not symlink to %r: %s') % |
524 (src, err.strerror), linkname) | 524 (src, err.strerror), linkname) |
525 else: | 525 else: |
526 self.write(dst, src) | 526 self.write(dst, src) |
527 | 527 |
1056 | 1056 |
1057 @staticmethod | 1057 @staticmethod |
1058 def stat(path): | 1058 def stat(path): |
1059 try: | 1059 try: |
1060 return util.cachestat(path) | 1060 return util.cachestat(path) |
1061 except OSError, e: | 1061 except OSError as e: |
1062 if e.errno != errno.ENOENT: | 1062 if e.errno != errno.ENOENT: |
1063 raise | 1063 raise |
1064 | 1064 |
1065 class filecacheentry(object): | 1065 class filecacheentry(object): |
1066 def __init__(self, paths, stat=True): | 1066 def __init__(self, paths, stat=True): |