comparison mercurial/patch.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 4b0fc75f9403
comparison
equal deleted inserted replaced
25659:d60678a567a9 25660:328739ea70c3
429 return (self.opener.readlink(fname), (True, False)) 429 return (self.opener.readlink(fname), (True, False))
430 430
431 isexec = False 431 isexec = False
432 try: 432 try:
433 isexec = self.opener.lstat(fname).st_mode & 0o100 != 0 433 isexec = self.opener.lstat(fname).st_mode & 0o100 != 0
434 except OSError, e: 434 except OSError as e:
435 if e.errno != errno.ENOENT: 435 if e.errno != errno.ENOENT:
436 raise 436 raise
437 try: 437 try:
438 return (self.opener.read(fname), (False, isexec)) 438 return (self.opener.read(fname), (False, isexec))
439 except IOError, e: 439 except IOError as e:
440 if e.errno != errno.ENOENT: 440 if e.errno != errno.ENOENT:
441 raise 441 raise
442 return None, None 442 return None, None
443 443
444 def setfile(self, fname, data, mode, copysource): 444 def setfile(self, fname, data, mode, copysource):
1361 l = ord(l) - ord('A') + 1 1361 l = ord(l) - ord('A') + 1
1362 else: 1362 else:
1363 l = ord(l) - ord('a') + 27 1363 l = ord(l) - ord('a') + 27
1364 try: 1364 try:
1365 dec.append(base85.b85decode(line[1:])[:l]) 1365 dec.append(base85.b85decode(line[1:])[:l])
1366 except ValueError, e: 1366 except ValueError as e:
1367 raise PatchError(_('could not decode "%s" binary patch: %s') 1367 raise PatchError(_('could not decode "%s" binary patch: %s')
1368 % (self._fname, str(e))) 1368 % (self._fname, str(e)))
1369 line = getline(lr, self.hunk) 1369 line = getline(lr, self.hunk)
1370 text = zlib.decompress(''.join(dec)) 1370 text = zlib.decompress(''.join(dec))
1371 if len(text) != size: 1371 if len(text) != size:
1936 backend.setfile(gp.path, data, mode, gp.oldpath) 1936 backend.setfile(gp.path, data, mode, gp.oldpath)
1937 continue 1937 continue
1938 try: 1938 try:
1939 current_file = patcher(ui, gp, backend, store, 1939 current_file = patcher(ui, gp, backend, store,
1940 eolmode=eolmode) 1940 eolmode=eolmode)
1941 except PatchError, inst: 1941 except PatchError as inst:
1942 ui.warn(str(inst) + '\n') 1942 ui.warn(str(inst) + '\n')
1943 current_file = None 1943 current_file = None
1944 rejects += 1 1944 rejects += 1
1945 continue 1945 continue
1946 elif state == 'git': 1946 elif state == 'git':