Coverage for src/lib/python/isc/cc/data : 99%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# Copyright (C) 2010 Internet Systems Consortium. # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# # Helper functions for data elements as used in cc-channel and # configuration. There is no python equivalent for the cpp Element # class, since data elements are represented by native python types # (int, real, bool, string, list and dict respectively) #
"""Raised if an identifier does not exist according to a spec file, or if an item is addressed that is not in the current (or default) config (such as a nonexistent list or map element)"""
"""Raised if there is an attemt to add an element to a list or a map that is already present in that list or map (i.e. if 'add' is used when it should be 'set')"""
"""Raised if there is an attempt to set an element that is of a different type than the type specified in the specification."""
"""Removes the values from dict a that are the same as in dict b. Raises a DataTypeError is a or b is not a dict"""
"""Merges the contents of new into orig, think recursive update() orig and new must both be dicts. If an element value is None in new it will be removed in orig."""
"""Recursively removes all (key,value) pairs from d where the value is None"""
"""Concatenates the given identifier parts into a string, delimited with the '/' character. """
"""Splits the given identifier into a list of identifier parts, as delimited by the '/' character. Raises a DataTypeError if identifier is not a string.""" raise DataTypeError("identifier is not a string")
"""Returns True if the given identifier string has at least one list index (with [I], where I is a number""" re.search("\[\d+\]", identifier) is not None)
"""Finds list indexes in the given identifier, which are of the format [integer]. Identifier must be a string. This will only give the list index for the last 'part' of the given identifier (as delimited by the '/' sign). Raises a DataTypeError if the identifier is not a string, or if the format is bad. Returns a tuple, where the first element is the string part of the identifier, and the second element is a list of (nested) list indices. Examples: 'a/b/c' will return ('a/b/c', None) 'a/b/c[1]' will return ('a/b/c', [1]) 'a/b/c[1][2][3]' will return ('a/b/c', [1, 2, 3]) 'a[0]/b[1]/c[2]' will return ('a[0]/b[1]/c', [2]) """ "split_identifier_list_indices() " "not a string: " + str(identifier))
# We only work on the final 'part' of the identifier
# keep the non-index part of that to replace later
# we replace the final part of the original identifier with # the stripped string
"""Finds the child of element with the given id. If the id contains [i], where i is a number, and the child element is a list, the i-th element of that list is returned instead of the list itself. Raises a DataTypeError if the element is of wrong type, if id is not a string, or if the id string contains a bad value. Raises a DataNotFoundError if the element at id could not be found. """ else:
"""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. """
"""Sets the value at the element specified by identifier to value. If the value is None, it is removed from the dict. If element is not a dict, or if the identifier points to something that is not, a DataTypeError is raised. The element is updated inline, so if the original needs to be kept, you must make a copy before calling set(). The updated base element is returned (so that el.set().set().set() is possible)""" # ok we are unsetting a value that wasn't set in # the first place. Simply stop.
# value can be an empty list or dict, so check for None eplicitely else: else: # in case of nested lists, we need to get to the next to last # value can be an empty list or dict, so check for None eplicitely else:
"""Removes the element at the given identifier if it exists. Raises a DataTypeError if element is not a dict or if identifier is not a string. Returns the base element.""" # perhaps we can simply do with set none, and remove this whole # function
"""Returns the subelement in the given data element, returns None if not found, or if an error occurred (i.e. this function should never raise an exception)"""
"""Parses the given string to a native python object. If the string cannot be parsed, it is returned. If it is not a string, None is returned""" # simply return the string itself
|