MCPcopy
hub / github.com/urllib3/urllib3 / to_bytes

Function to_bytes

src/urllib3/util/util.py:7–16  ·  view source on GitHub ↗
(
    x: str | bytes, encoding: str | None = None, errors: str | None = None
)

Source from the content-addressed store, hash-verified

5
6
7def to_bytes(
8 x: str | bytes, encoding: str | None = None, errors: str | None = None
9) -> bytes:
10 if isinstance(x, bytes):
11 return x
12 elif not isinstance(x, str):
13 raise TypeError(f"not expecting type {type(x).__name__}")
14 if encoding or errors:
15 return x.encode(encoding or "utf-8", errors=errors or "strict")
16 return x.encode()
17
18
19def to_str(

Callers 3

test_to_bytesMethod · 0.90
test_to_bytes_errorMethod · 0.90
body_to_chunksFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_to_bytesMethod · 0.72
test_to_bytes_errorMethod · 0.72