[svn] commit: r3722 - in /branches/trac405/src/lib/python/isc/cc: data.py tests/data_test.py

BIND 10 source code commits bind10-changes at lists.isc.org
Sun Dec 5 22:01:14 UTC 2010


Author: jelte
Date: Sun Dec  5 22:01:13 2010
New Revision: 3722

Log:
refactor code for readability

Modified:
    branches/trac405/src/lib/python/isc/cc/data.py
    branches/trac405/src/lib/python/isc/cc/tests/data_test.py

Modified: branches/trac405/src/lib/python/isc/cc/data.py
==============================================================================
--- branches/trac405/src/lib/python/isc/cc/data.py (original)
+++ branches/trac405/src/lib/python/isc/cc/data.py Sun Dec  5 22:01:13 2010
@@ -150,8 +150,17 @@
     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

Modified: branches/trac405/src/lib/python/isc/cc/tests/data_test.py
==============================================================================
--- branches/trac405/src/lib/python/isc/cc/tests/data_test.py (original)
+++ branches/trac405/src/lib/python/isc/cc/tests/data_test.py Sun Dec  5 22:01:13 2010
@@ -137,6 +137,7 @@
         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")
 




More information about the bind10-changes mailing list