def _type()

in c3dm/tools/tabulate.py [0:0]


def _type(string, has_invisible=True, numparse=True):
	"""The least generic type (type(None), int, float, str, unicode).

	>>> _type(None) is type(None)
	True
	>>> _type("foo") is type("")
	True
	>>> _type("1") is type(1)
	True
	>>> _type('\x1b[31m42\x1b[0m') is type(42)
	True
	>>> _type('\x1b[31m42\x1b[0m') is type(42)
	True

	"""

	if has_invisible and \
	   (isinstance(string, _text_type) or isinstance(string, _binary_type)):
		string = _strip_invisible(string)

	if string is None:
		return _none_type
	elif hasattr(string, "isoformat"):  # datetime.datetime, date, and time
		return _text_type
	elif _isbool(string):
		return _bool_type
	elif _isint(string) and numparse:
		return int
	elif _isint(string, _long_type) and numparse:
		return int
	elif _isnumber(string) and numparse:
		return float
	elif isinstance(string, _binary_type):
		return _binary_type
	else:
		return _text_type