Remove singledispatch import conditional

This commit is contained in:
Nikolaus Waxweiler 2019-10-12 12:20:06 +01:00
parent 969df8303b
commit b0afdc273e

View File

@ -364,12 +364,6 @@ def _string_or_data_element(raw_bytes, ctx):
return _string_element(string, ctx)
# if singledispatch is available, we use a generic '_make_element' function
# and register overloaded implementations that are run based on the type of
# the first argument
if singledispatch is not None:
@singledispatch
def _make_element(value, ctx):
raise TypeError("unsupported type: %s" % type(value))
@ -386,31 +380,6 @@ if singledispatch is not None:
_make_element.register(bytearray)(_data_element)
_make_element.register(Data)(lambda v, ctx: _data_element(v.data, ctx))
else:
# otherwise we use a long switch-like if statement
def _make_element(value, ctx):
if isinstance(value, unicode):
return _string_element(value, ctx)
elif isinstance(value, bool):
return _bool_element(value, ctx)
elif isinstance(value, Integral):
return _integer_element(value, ctx)
elif isinstance(value, float):
return _real_element(value, ctx)
elif isinstance(value, Mapping):
return _dict_element(value, ctx)
elif isinstance(value, (list, tuple)):
return _array_element(value, ctx)
elif isinstance(value, datetime):
return _date_element(value, ctx)
elif isinstance(value, bytes):
return _string_or_data_element(value, ctx)
elif isinstance(value, bytearray):
return _data_element(value, ctx)
elif isinstance(value, Data):
return _data_element(value.data, ctx)
# Public functions to create element tree from plist-compatible python
# data structures and viceversa, for use when (de)serializing GLIF xml.