# Path: riv/utils.py
# def traverse_dict(d, keys, return_parent=False):
#     if return_parent:
#         # Remove the last key element and set return_parent to False
#         # for recursive calls.
#         keys = keys[:-1]
#         return_parent = False
#     if isinstance(d, dict) and len(keys) > 0:
#         if d.has_key(keys[0]):
#             return traverse_dict(d[keys[0]], keys[1:], return_parent)
#         else:
#             raise KeyError("Traversing the dictionary failed on key: %s" % keys[0])
#     elif isinstance(d, list) and len(keys) == 1:
#         try:
#             if isinstance(d[0], dict):
#                 try:
#                     return [i[keys[0]] for i in d]
#                 except KeyError, e:
#                     raise KeyError("Traversing the dictionary failed on key: %s" % keys[0])
#         except IndexError, e:
#             raise KeyError("Traversing the dictionary failed on key: %s" % keys[0])
#     else:
#         # if "keys" is specified the user requested to further traverse
#         # the dictionary. This fails so we return None. In any other
#         # case we arrived and return the value. 
#         if keys:
#             raise KeyError("Traversing the dictionary failed on key: %s" % keys[0])
#         else:
#             return d


import datetime
from django.test import Client, TestCase
from riv.utils import traverse_dict
from polls.tests import BaseTestCase
            traverse_dict(self.d, ['a', 'b', 'c']),
            'value'
        )

    def testTraverseSimple2(self):
        self.assertEqual(
            traverse_dict(self.d, ['a', 'b']),
            {'c': 'value'}
        )

    def testTraverseSimpleReturnParent(self):
        self.assertEqual(
            traverse_dict(self.d, ['a', 'b', 'c'], return_parent=True),
            {'c': 'value'}
        )

    def testTraverseList(self):
        self.assertEqual(
            traverse_dict(self.d_list, ['a', 'b', 'c']),
            ['value1', 'value2']
        )

    def testTraverseList2(self):
        self.assertEqual(
            traverse_dict(self.d_list, ['a', 'b']),
            [{'c': 'value1'}, {'c': 'value2'}]
        )

    def testTraverseListReturnParent(self):
        self.assertEqual(

# Path: riv/utils.py
# def traverse_dict(d, keys, return_parent=False):
#     if return_parent:
#         # Remove the last key element and set return_parent to False
#         # for recursive calls.
#         keys = keys[:-1]
#         return_parent = False
#     if isinstance(d, dict) and len(keys) > 0:
#         if d.has_key(keys[0]):
#             return traverse_dict(d[keys[0]], keys[1:], return_parent)
#         else:
#             raise KeyError("Traversing the dictionary failed on key: %s" % keys[0])
#     elif isinstance(d, list) and len(keys) == 1:
#         try:
#             if isinstance(d[0], dict):
#                 try:
#                     return [i[keys[0]] for i in d]
#                 except KeyError, e:
#                     raise KeyError("Traversing the dictionary failed on key: %s" % keys[0])
#         except IndexError, e:
#             raise KeyError("Traversing the dictionary failed on key: %s" % keys[0])
#     else:
#         # if "keys" is specified the user requested to further traverse
#         # the dictionary. This fails so we return None. In any other
#         # case we arrived and return the value. 
#         if keys:
#             raise KeyError("Traversing the dictionary failed on key: %s" % keys[0])
#         else:
#             return d


# Path: tests/polls/tests/utils.py
import datetime
from django.test import Client, TestCase
from riv.utils import traverse_dict
from polls.tests import BaseTestCase

            traverse_dict(self.d, ['a', 'b', 'c']),
            'value'
        )

    def testTraverseSimple2(self):
        self.assertEqual(
            traverse_dict(self.d, ['a', 'b']),
            {'c': 'value'}
        )

    def testTraverseSimpleReturnParent(self):
        self.assertEqual(
            traverse_dict(self.d, ['a', 'b', 'c'], return_parent=True),
            {'c': 'value'}
        )

    def testTraverseList(self):
        self.assertEqual(
            traverse_dict(self.d_list, ['a', 'b', 'c']),
            ['value1', 'value2']
        )

    def testTraverseList2(self):
        self.assertEqual(
            traverse_dict(self.d_list, ['a', 'b']),
            [{'c': 'value1'}, {'c': 'value2'}]
        )

    def testTraverseListReturnParent(self):
        self.assertEqual(

            traverse_dict(self.d_list, ['a', 'b', 'c'], return_parent=True),