comparison mercurial/revlog.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 0bda5bfaf0b1
children 00e3f909907f
comparison
equal deleted inserted replaced
25659:d60678a567a9 25660:328739ea70c3
87 if t == '\0': 87 if t == '\0':
88 return bin 88 return bin
89 if t == 'x': 89 if t == 'x':
90 try: 90 try:
91 return _decompress(bin) 91 return _decompress(bin)
92 except zlib.error, e: 92 except zlib.error as e:
93 raise RevlogError(_("revlog decompress error: %s") % str(e)) 93 raise RevlogError(_("revlog decompress error: %s") % str(e))
94 if t == 'u': 94 if t == 'u':
95 return bin[1:] 95 return bin[1:]
96 raise RevlogError(_("unknown compression type %r") % t) 96 raise RevlogError(_("unknown compression type %r") % t)
97 97
244 i = f.read() 244 i = f.read()
245 f.close() 245 f.close()
246 if len(i) > 0: 246 if len(i) > 0:
247 v = struct.unpack(versionformat, i[:4])[0] 247 v = struct.unpack(versionformat, i[:4])[0]
248 self._initempty = False 248 self._initempty = False
249 except IOError, inst: 249 except IOError as inst:
250 if inst.errno != errno.ENOENT: 250 if inst.errno != errno.ENOENT:
251 raise 251 raise
252 252
253 self.version = v 253 self.version = v
254 self._inline = v & REVLOGNGINLINEDATA 254 self._inline = v & REVLOGNGINLINEDATA
1569 f = self.opener(self.datafile) 1569 f = self.opener(self.datafile)
1570 f.seek(0, 2) 1570 f.seek(0, 2)
1571 actual = f.tell() 1571 actual = f.tell()
1572 f.close() 1572 f.close()
1573 dd = actual - expected 1573 dd = actual - expected
1574 except IOError, inst: 1574 except IOError as inst:
1575 if inst.errno != errno.ENOENT: 1575 if inst.errno != errno.ENOENT:
1576 raise 1576 raise
1577 dd = 0 1577 dd = 0
1578 1578
1579 try: 1579 try:
1588 databytes = 0 1588 databytes = 0
1589 for r in self: 1589 for r in self:
1590 databytes += max(0, self.length(r)) 1590 databytes += max(0, self.length(r))
1591 dd = 0 1591 dd = 0
1592 di = actual - len(self) * s - databytes 1592 di = actual - len(self) * s - databytes
1593 except IOError, inst: 1593 except IOError as inst:
1594 if inst.errno != errno.ENOENT: 1594 if inst.errno != errno.ENOENT:
1595 raise 1595 raise
1596 di = 0 1596 di = 0
1597 1597
1598 return (dd, di) 1598 return (dd, di)