MCPcopy
hub / github.com/psf/requests / to_native_string

Function to_native_string

src/requests/_internal_utils.py:26–36  ·  view source on GitHub ↗

Given a string object, regardless of type, returns a representation of that string in the native string type, encoding and decoding where necessary. This assumes ASCII unless told otherwise.

(string: str | bytes, encoding: str = "ascii")

Source from the content-addressed store, hash-verified

24
25
26def to_native_string(string: str | bytes, encoding: str = "ascii") -> str:
27 """Given a string object, regardless of type, returns a representation of
28 that string in the native string type, encoding and decoding where
29 necessary. This assumes ASCII unless told otherwise.
30 """
31 if isinstance(string, builtin_str):
32 out = string
33 else:
34 out = string.decode(encoding)
35
36 return out
37
38
39def unicode_is_ascii(u_string: str) -> bool:

Callers 8

test_to_native_stringFunction · 0.90
_basic_auth_strFunction · 0.85
get_full_urlMethod · 0.85
prepare_methodMethod · 0.85
prepare_urlMethod · 0.85
prepare_headersMethod · 0.85
get_redirect_targetMethod · 0.85
resolve_redirectsMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_to_native_stringFunction · 0.72