MCPcopy Create free account
hub / github.com/ExpressLRS/ExpressLRS / ensure_binary

Function ensure_binary

src/python/external/six.py:898–913  ·  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

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

Callers

nothing calls this directly

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected