Handle IndexError for integer ParamList lookups.

We expect ParamList objects to use strings for their
indexes like AssociatedDeviceList['1'], but we transparently
handle the older convention of using Integers.

That integer fallback was only handling KeyError, as from a dict,
but data models using AutoDict like brcmwifi.py would raise an
IndexError instead. Add a test to demonstrate the problem, then
fix it.

Fixes b/33414470.
Fixes remaining symptom of b/29127321.

Change-Id: I7234d330c0bffec6f6418c468af8cd9f7a019841
diff --git a/tr/core_test.py b/tr/core_test.py
index 803959f..a6ff82c 100644
--- a/tr/core_test.py
+++ b/tr/core_test.py
@@ -81,6 +81,26 @@
       self.Count = self.gcount[0]
 
 
+class IndexErrorAutoObject(core.Exporter):
+
+  def __init__(self):
+    core.Exporter.__init__(self)
+    self.SubList = core.AutoDict('SubList',
+                                 iteritems=self._itersubs,
+                                 getitem=self._getsub)
+    self.Export(lists=['Sub'])
+
+  def _itersubs(self):
+    for i in range(3):
+      yield i, i
+
+  def _getsub(self, key):
+    if isinstance(key, int):
+      raise IndexError('Testing IndexError for an integer index')
+    else:
+      return int(key)
+
+
 class CoreTest(unittest.TestCase):
 
   def setUp(self):
@@ -270,6 +290,13 @@
       h.SetExportParam('ReadParam', 6)
     self.gccheck.Check()
 
+  def testIndexError(self):
+    """Test for b/33414470."""
+    root = IndexErrorAutoObject()
+    h = handle.Handle(root)
+    self.assertEqual(h.GetExport('Sub.1'), 1)
+    self.gccheck.Check()
+
 
 if __name__ == '__main__':
   unittest.main()
diff --git a/tr/handle.py b/tr/handle.py
index 18f15cf..3ea23cb 100644
--- a/tr/handle.py
+++ b/tr/handle.py
@@ -222,7 +222,7 @@
     iname = _Int(name)
     try:
       return parent[iname]
-    except KeyError:
+    except (KeyError, IndexError):
       pass
     return parent[name]