MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / ensure_text

Function ensure_text

pager_lib/six.py:944–960  ·  view source on GitHub ↗

Coerce *s* to six.text_type. For Python 2: - `unicode` -> `unicode` - `str` -> `unicode` For Python 3: - `str` -> `str` - `bytes` -> decoded to `str`

(s, encoding='utf-8', errors='strict')

Source from the content-addressed store, hash-verified

942
943
944def ensure_text(s, encoding='utf-8', errors='strict'):
945 """Coerce *s* to six.text_type.
946
947 For Python 2:
948 - `unicode` -> `unicode`
949 - `str` -> `unicode`
950
951 For Python 3:
952 - `str` -> `str`
953 - `bytes` -> decoded to `str`
954 """
955 if isinstance(s, binary_type):
956 return s.decode(encoding, errors)
957 elif isinstance(s, text_type):
958 return s
959 else:
960 raise TypeError("not expecting type '%s'" % type(s))
961
962
963def python_2_unicode_compatible(klass):

Callers

nothing calls this directly

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected