24 from past.builtins
import basestring
27 from collections.abc
import Sequence, Set, Mapping
29 from collections
import Sequence, Set, Mapping
35 """Takes any object and puts that whole object in a list: 36 - strings will be made into a single element in the list 37 - tuples will be converted to list 38 - lists will remain as lists 39 - None will be made into an empty list 43 elif isinstance(x, basestring):
45 elif isinstance(x, dict):
47 elif hasattr(x,
'__iter__'):
55 """Takes any object. Returns it if it is iterable. If it 56 is not iterable it puts the object in a list and returns 57 the list. None will return an empty list. If a new list 58 is always required use listify(). Strings will be placed 59 in a list with a single element. 63 elif isinstance(x, basestring):
65 elif hasattr(x,
'__iter__'):
73 """Takes an object, if it is a sequence return it, 74 else put it in a tuple. Strings are not sequences. 75 If x is a dict, returns a sorted tuple of keys.""" 76 if isinstance(x, (Sequence, Set))
and not isinstance(x, basestring):
78 elif isinstance(x, Mapping):
79 x = tuple(sorted(x.keys()))
86 """Take an object x and return it in a set. 88 If x is a container, will create a set from the contents of the container. 89 If x is an object, will create a set with a single item in it. 90 If x is a string, will treat the string as a single object (i.e. not as a list of chars)""" 99 if isinstance(x, basestring):
110 """Import a python object given an importable string""" 112 if not isinstance(pythonType, basestring):
113 raise TypeError(
"Unhandled type of pythonType, val:%s" % pythonType)
116 pythonTypeTokenList = str(pythonType).split(
'.')
117 importClassString = pythonTypeTokenList.pop()
118 importClassString = importClassString.strip()
119 importPackage =
".".join(pythonTypeTokenList)
120 importType = __import__(importPackage, globals(), locals(), [importClassString], 0)
121 pythonType = getattr(importType, importClassString)
126 pythonTypeTokenList = pythonType.split(
'.')
127 importClassString =
'.'.join(pythonTypeTokenList[0:-1])
128 importedClass =
doImport(importClassString)
129 pythonType = getattr(importedClass, pythonTypeTokenList[-1])