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

Remove exception indexing

This commit is contained in:
Mike Naberezny 2013-10-26 13:55:02 -07:00
parent ee02520689
commit 455fb5da2d
3 changed files with 16 additions and 15 deletions

View File

@ -54,7 +54,7 @@ class Monitor(cmd.Cmd):
longopts = ['help', 'mpu=', 'load=', 'rom=', 'goto=']
options, args = getopt.getopt(argv[1:], shortopts, longopts)
except getopt.GetoptError as exc:
self._output(str(exc))
self._output(exc.message)
self._usage()
self._exit(1)
@ -507,7 +507,7 @@ class Monitor(cmd.Cmd):
intval &= self.byteMask
setattr(self._mpu, register, intval)
except KeyError as exc:
self._output(exc[0])
self._output(exc.message)
def help_cd(self):
self._output("cd <directory>")
@ -520,7 +520,8 @@ class Monitor(cmd.Cmd):
try:
os.chdir(args)
except OSError as exc:
msg = "Cannot change directory: [%d] %s" % (exc[0], exc[1])
msg = "Cannot change directory: [%d] %s" % (exc.errno,
exc.strerror)
self._output(msg)
self.do_pwd()
@ -550,7 +551,7 @@ class Monitor(cmd.Cmd):
bytes = f.read()
f.close()
except (urllib2.URLError, urllib2.HTTPError) as exc:
msg = "Cannot fetch remote file: %s" % str(exc)
msg = "Cannot fetch remote file: %s" % exc.message
self._output(msg)
return
else:
@ -559,7 +560,7 @@ class Monitor(cmd.Cmd):
bytes = f.read()
f.close()
except (OSError, IOError) as exc:
msg = "Cannot load file: [%d] %s" % (exc[0], exc[1])
msg = "Cannot load file: [%d] %s" % (exc.errno, exc.strerror)
self._output(msg)
return
@ -601,7 +602,7 @@ class Monitor(cmd.Cmd):
f.write(chr((byte >> shift) & 0xff))
f.close()
except (OSError, IOError) as exc:
msg = "Cannot save file: [%d] %s" % (exc[0], exc[1])
msg = "Cannot save file: [%d] %s" % (exc.errno, exc.strerror)
self._output(msg)
return

View File

@ -50,7 +50,7 @@ class AddressParserTests(unittest.TestCase):
parser.number('bad_label')
self.fail()
except KeyError as exc:
self.assertEqual('Label not found: bad_label', exc[0])
self.assertEqual('Label not found: bad_label', exc.message)
def test_number_label_hex_offset(self):
parser = AddressParser()
@ -96,7 +96,7 @@ class AddressParserTests(unittest.TestCase):
parser.number('bad_label+3')
self.fail()
except KeyError as exc:
self.assertEqual('Label not found: bad_label', exc[0])
self.assertEqual('Label not found: bad_label', exc.message)
def test_number_bad_label_syntax(self):
parser = AddressParser()
@ -105,7 +105,7 @@ class AddressParserTests(unittest.TestCase):
parser.number('#$foo')
self.fail()
except KeyError as exc:
self.assertEqual('Label not found: #$foo', exc[0])
self.assertEqual('Label not found: #$foo', exc.message)
def test_number_constrains_address_at_zero_or_above(self):
parser = AddressParser()

View File

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