RestOC.DictHelper module

Dictionary Helper Module

Several useful helper methods for use with dicts

RestOC.DictHelper.clone(src)

Clone

Goes through the dict and any child dicts copying the values so that we don’t have any references

Parameters

src (dict) – The source dict

Returns

dict

RestOC.DictHelper.combine(first, second)

Combine

Generates a new dict by combining the two passed, values in second will overwrite values in first

Parameters
  • first (dict) – The dict to be changed/overwritten

  • second (dict) – The dict that will do the overwriting

Returns

dict

RestOC.DictHelper.eval(src, contains)

Eval(uate)

Goes through a dict looking for keys from contains

Parameters
  • src (dict) – The dict we are evaluating

  • contains (list) – A list of values to check for, if the value is a dict rather than a string, epects keys to be keys pointing to further lists of keys

Returns

A list of errors, or None

RestOC.DictHelper.keysToInts(src)

Keys To Ints

Recursively goes through a dictionary and converts all keys that are numeric but stored as strings to integers. Returns a new dict and doesn’t alter the original.

PLEASE NOTE: this method is not useful for classes, or anything complex, it is meant primarily for converting JSON objects which don’t allow ints as keys. Passing a set, tuple, or iterable class will not result in the expected result

Parameters

src (dict|list) – The dict we are modifying, accepts lists in order to handle recursive following the data

Returns

dict|list