if not PY2:
text_type = str
+ binary_type = bytes
string_types = (str,)
integer_types = (int, )
- unichr = chr
text_to_native = lambda s, enc: s
+ unichr = chr
iterkeys = lambda d: iter(d.keys())
itervalues = lambda d: iter(d.values())
else:
text_type = unicode
+ binary_type = str
string_types = (str, unicode)
integer_types = (int, long)
number_types = integer_types + (float,)
+def force_text(s, encoding='utf-8', errors='strict'):
+ if isinstance(s, text_type):
+ return s
+ if isinstance(s, binary_type):
+ return s.decode(encoding, errors)
+ return text_type(s)
+
+
#
# Since Python 3.3, a fast decimal implementation is already included in the
# standard library. Otherwise use cdecimal when available