24 from collections.abc
import Sequence, Set, Mapping
30 """Takes any object and puts that whole object in a list:
31 - strings will be made into a single element in the list
32 - tuples will be converted to list
33 - lists will remain as lists
34 - None will be made into an empty list
38 elif isinstance(x, str):
40 elif isinstance(x, dict):
42 elif hasattr(x,
'__iter__'):
50 """Takes any object. Returns it if it is iterable. If it
51 is not iterable it puts the object in a list and returns
52 the list. None will return an empty list. If a new list
53 is always required use listify(). Strings will be placed
54 in a list with a single element.
58 elif isinstance(x, str):
60 elif hasattr(x,
'__iter__'):
68 """Takes an object, if it is a sequence return it,
69 else put it in a tuple. Strings are not sequences.
70 If x is a dict, returns a sorted tuple of keys."""
71 if isinstance(x, (Sequence, Set))
and not isinstance(x, str):
73 elif isinstance(x, Mapping):
74 x = tuple(sorted(x.keys()))
81 """Take an object x and return it in a set.
83 If x is a container, will create a set from the contents of the container.
84 If x is an object, will create a set with a single item in it.
85 If x is a string, will treat the string as a single object (i.e. not as a list of chars)"""
94 if isinstance(x, str):
105 """Import a python object given an importable string"""
107 if not isinstance(pythonType, str):
108 raise TypeError(
"Unhandled type of pythonType, val:%s" % pythonType)
110 pythonTypeTokenList = pythonType.split(
'.')
111 importClassString = pythonTypeTokenList.pop()
112 importClassString = importClassString.strip()
113 importPackage =
".".join(pythonTypeTokenList)
114 importType = __import__(importPackage, globals(), locals(), [importClassString], 0)
115 pythonType = getattr(importType, importClassString)
120 pythonTypeTokenList = pythonType.split(
'.')
121 importClassString =
'.'.join(pythonTypeTokenList[0:-1])
122 importedClass =
doImport(importClassString)
123 pythonType = getattr(importedClass, pythonTypeTokenList[-1])