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

Function ensure_binary

pager_lib/six.py:903–918  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

901
902
903def ensure_binary(s, encoding='utf-8', errors='strict'):
904 """Coerce **s** to six.binary_type.
905
906 For Python 2:
907 - `unicode` -> encoded to `str`
908 - `str` -> `str`
909
910 For Python 3:
911 - `str` -> encoded to `bytes`
912 - `bytes` -> `bytes`
913 """
914 if isinstance(s, binary_type):
915 return s
916 if isinstance(s, text_type):
917 return s.encode(encoding, errors)
918 raise TypeError("not expecting type '%s'" % type(s))
919
920
921def ensure_str(s, encoding='utf-8', errors='strict'):

Callers

nothing calls this directly

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected