forked from ipfs-shipyard/py-ipfs-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.py
55 lines (45 loc) · 1.33 KB
/
http.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Default HTTP client selection proxy"""
import os
import typing as ty
from .http_common import (
ClientSyncBase,
StreamDecodeIteratorSync,
addr_t, auth_t, cookies_t, headers_t, params_t, reqdata_sync_t, timeout_t,
workarounds_t,
)
__all__ = (
"addr_t", "auth_t", "cookies_t", "headers_t", "params_t", "reqdata_sync_t",
"timeout_t", "workarounds_t",
"build_client_sync",
"StreamDecodeIteratorSync",
)
PREFER_HTTPX = (os.environ.get("PY_IPFS_HTTP_CLIENT_PREFER_HTTPX", "no").lower()
not in ("0", "f", "false", "n", "no"))
if PREFER_HTTPX: # pragma: http-backend=httpx
try:
from . import http_httpx as _backend
except ImportError:
from . import http_requests as _backend # type: ignore[no-redef]
else: # pragma: http-backend=requests
try:
from . import http_requests as _backend # type: ignore[no-redef]
except ImportError: # pragma: no cover
from . import http_httpx as _backend
def build_client_sync( # type: ignore[no-any-unimported]
addr: addr_t,
base: str,
offline: bool = False,
auth: auth_t = None,
cookies: cookies_t = None,
headers: headers_t = None,
timeout: timeout_t = 120
) -> ClientSyncBase[ty.Any]:
return _backend.ClientSync(
addr=addr,
base=base,
offline=offline,
auth=auth,
cookies=cookies,
headers=headers or ty.cast(ty.Dict[str, str], {}),
timeout=timeout
)