24 from past.builtins
import basestring
26 from collections.abc
import Sequence, Set, Mapping
32 """Takes any object and puts that whole object in a list: 33 - strings will be made into a single element in the list 34 - tuples will be converted to list 35 - lists will remain as lists 36 - None will be made into an empty list 40 elif isinstance(x, basestring):
42 elif isinstance(x, dict):
44 elif hasattr(x,
'__iter__'):
52 """Takes any object. Returns it if it is iterable. If it 53 is not iterable it puts the object in a list and returns 54 the list. None will return an empty list. If a new list 55 is always required use listify(). Strings will be placed 56 in a list with a single element. 60 elif isinstance(x, basestring):
62 elif hasattr(x,
'__iter__'):
70 """Takes an object, if it is a sequence return it, 71 else put it in a tuple. Strings are not sequences. 72 If x is a dict, returns a sorted tuple of keys.""" 73 if isinstance(x, (Sequence, Set))
and not isinstance(x, basestring):
75 elif isinstance(x, Mapping):
76 x = tuple(sorted(x.keys()))
83 """Take an object x and return it in a set. 85 If x is a container, will create a set from the contents of the container. 86 If x is an object, will create a set with a single item in it. 87 If x is a string, will treat the string as a single object (i.e. not as a list of chars)""" 96 if isinstance(x, basestring):
107 """Import a python object given an importable string""" 109 if not isinstance(pythonType, basestring):
110 raise TypeError(
"Unhandled type of pythonType, val:%s" % pythonType)
113 pythonTypeTokenList = str(pythonType).split(
'.')
114 importClassString = pythonTypeTokenList.pop()
115 importClassString = importClassString.strip()
116 importPackage =
".".join(pythonTypeTokenList)
117 importType = __import__(importPackage, globals(), locals(), [importClassString], 0)
118 pythonType = getattr(importType, importClassString)
123 pythonTypeTokenList = pythonType.split(
'.')
124 importClassString =
'.'.join(pythonTypeTokenList[0:-1])
125 importedClass =
doImport(importClassString)
126 pythonType = getattr(importedClass, pythonTypeTokenList[-1])