Commit 8b07c253 authored by Jelte Jansen's avatar Jelte Jansen

refactor code for readability


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac405@3722 e5f2f494-b856-4b98-b285-d166d9295462
parent af62c6c6
......@@ -150,8 +150,17 @@ def _find_child_el(element, id):
return result
def find(element, identifier):
"""Returns the subelement in the given data element, raises DataNotFoundError if not found"""
if (type(element) != dict and identifier != ""):
"""Returns the subelement in the given data element, raises
DataNotFoundError if not found.
Returns the given element if the identifier is an empty string.
Raises a DataTypeError if identifier is not a string, or if
identifier is not empty, and element is not a dict.
"""
if type(identifier) != str:
raise DataTypeError("identifier in find() is not a str")
if identifier == "":
return element
if type(element) != dict:
raise DataTypeError("element in find() is not a dict")
id_parts = split_identifier(identifier)
cur_el = element
......
......@@ -137,6 +137,7 @@ class TestData(unittest.TestCase):
self.assertRaises(data.DataNotFoundError, data.find, d1, 'f')
self.assertRaises(data.DataTypeError, data.find, d1, 1)
self.assertRaises(data.DataTypeError, data.find, None, 1)
self.assertRaises(data.DataTypeError, data.find, None, "foo")
self.assertRaises(data.DataTypeError, data.find, "123", "123")
self.assertEqual(data.find("123", ""), "123")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment