1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-12-29 06:29:48 +00:00

Remove old exception syntax

This commit is contained in:
Mike Naberezny 2013-10-26 13:39:35 -07:00
parent 78d8852e18
commit ee02520689
3 changed files with 31 additions and 31 deletions

View File

@ -53,8 +53,8 @@ class Monitor(cmd.Cmd):
shortopts = 'hm:l:r:g:'
longopts = ['help', 'mpu=', 'load=', 'rom=', 'goto=']
options, args = getopt.getopt(argv[1:], shortopts, longopts)
except getopt.GetoptError, err:
self._output(str(err))
except getopt.GetoptError as exc:
self._output(str(exc))
self._usage()
self._exit(1)
@ -104,7 +104,7 @@ class Monitor(cmd.Cmd):
result = cmd.Cmd.onecmd(self, line)
except KeyboardInterrupt:
self._output("Interrupt")
except Exception, e:
except Exception:
(file, fun, line), t, v, tbinfo = compact_traceback()
error = 'Error: %s, %s: file: %s line: %s' % (t, v, file, line)
self._output(error)
@ -506,8 +506,8 @@ class Monitor(cmd.Cmd):
if len(register) == 1:
intval &= self.byteMask
setattr(self._mpu, register, intval)
except KeyError, why:
self._output(why[0])
except KeyError as exc:
self._output(exc[0])
def help_cd(self):
self._output("cd <directory>")
@ -519,8 +519,8 @@ class Monitor(cmd.Cmd):
try:
os.chdir(args)
except OSError, why:
msg = "Cannot change directory: [%d] %s" % (why[0], why[1])
except OSError as exc:
msg = "Cannot change directory: [%d] %s" % (exc[0], exc[1])
self._output(msg)
self.do_pwd()
@ -549,8 +549,8 @@ class Monitor(cmd.Cmd):
f = urllib2.urlopen(filename)
bytes = f.read()
f.close()
except (urllib2.URLError, urllib2.HTTPError), why:
msg = "Cannot fetch remote file: %s" % str(why)
except (urllib2.URLError, urllib2.HTTPError) as exc:
msg = "Cannot fetch remote file: %s" % str(exc)
self._output(msg)
return
else:
@ -558,8 +558,8 @@ class Monitor(cmd.Cmd):
f = open(filename, 'rb')
bytes = f.read()
f.close()
except (OSError, IOError), why:
msg = "Cannot load file: [%d] %s" % (why[0], why[1])
except (OSError, IOError) as exc:
msg = "Cannot load file: [%d] %s" % (exc[0], exc[1])
self._output(msg)
return
@ -600,8 +600,8 @@ class Monitor(cmd.Cmd):
for shift in range(self.byteWidth - 8, -1, -8):
f.write(chr((byte >> shift) & 0xff))
f.close()
except (OSError, IOError), why:
msg = "Cannot save file: [%d] %s" % (why[0], why[1])
except (OSError, IOError) as exc:
msg = "Cannot save file: [%d] %s" % (exc[0], exc[1])
self._output(msg)
return

View File

@ -49,8 +49,8 @@ class AddressParserTests(unittest.TestCase):
try:
parser.number('bad_label')
self.fail()
except KeyError, why:
self.assertEqual('Label not found: bad_label', why[0])
except KeyError as exc:
self.assertEqual('Label not found: bad_label', exc[0])
def test_number_label_hex_offset(self):
parser = AddressParser()
@ -95,8 +95,8 @@ class AddressParserTests(unittest.TestCase):
try:
parser.number('bad_label+3')
self.fail()
except KeyError, why:
self.assertEqual('Label not found: bad_label', why[0])
except KeyError as exc:
self.assertEqual('Label not found: bad_label', exc[0])
def test_number_bad_label_syntax(self):
parser = AddressParser()
@ -104,8 +104,8 @@ class AddressParserTests(unittest.TestCase):
try:
parser.number('#$foo')
self.fail()
except KeyError, why:
self.assertEqual('Label not found: #$foo', why[0])
except KeyError as exc:
self.assertEqual('Label not found: #$foo', exc[0])
def test_number_constrains_address_at_zero_or_above(self):
parser = AddressParser()

View File

@ -29,55 +29,55 @@ class HexdumpLoaderTests(unittest.TestCase):
try:
Loader(text)
self.fail()
except ValueError, why:
except ValueError as exc:
msg = 'Start address was not found in data'
self.assert_(why[0].startswith('Start address'))
self.assert_(exc[0].startswith('Start address'))
def test_raises_when_start_address_is_invalid(self):
text = 'oops: aa bb cc'
try:
Loader(text)
self.fail()
except ValueError, why:
except ValueError as exc:
msg = 'Could not parse address: oops'
self.assertEqual(msg, why[0])
self.assertEqual(msg, exc[0])
def test_raises_when_start_address_is_too_short(self):
text = '01: aa bb cc'
try:
Loader(text)
self.fail()
except ValueError, why:
except ValueError as exc:
msg = 'Expected address to be 2 bytes, got 1'
self.assertEqual(msg, why[0])
self.assertEqual(msg, exc[0])
def test_raises_when_start_address_is_too_long(self):
text = '010304: aa bb cc'
try:
Loader(text)
self.fail()
except ValueError, why:
except ValueError as exc:
msg = 'Expected address to be 2 bytes, got 3'
self.assertEqual(msg, why[0])
self.assertEqual(msg, exc[0])
def test_raises_when_next_address_is_unexpected(self):
text = "c000: aa\nc002: cc"
try:
Loader(text)
self.fail()
except ValueError, why:
except ValueError as exc:
msg = 'Non-contigous block detected. Expected next ' \
'address to be $c001, label was $c002'
self.assertEqual(msg, why[0])
self.assertEqual(msg, exc[0])
def test_raises_when_data_is_invalid(self):
text = 'c000: foo'
try:
Loader(text)
self.fail()
except ValueError, why:
except ValueError as exc:
msg = 'Could not parse data: foo'
self.assertEqual(msg, why[0])
self.assertEqual(msg, exc[0])
def test_loads_data_without_dollar_signs(self):
text = 'c000: aa bb'