mirror of
https://github.com/httpie/cli.git
synced 2025-03-13 14:28:50 +01:00
Cleanup
This commit is contained in:
parent
65e44228be
commit
b58d001177
@ -123,14 +123,15 @@ def collect_messages(
|
|||||||
happy_eyeballs=args.happy_eyeballs,
|
happy_eyeballs=args.happy_eyeballs,
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.disable_http3 is False and args.force_http3 is True:
|
if not args.disable_http3 and args.force_http3:
|
||||||
requests_session.quic_cache_layer[(parsed_url.host, parsed_url.port or 443)] = (parsed_url.host, parsed_url.port or 443)
|
requests_session.quic_cache_layer[(parsed_url.host, parsed_url.port or 443)] = (parsed_url.host, parsed_url.port or 443)
|
||||||
# well, this one is tricky. If we allow HTTP/3, and remote host was marked as QUIC capable
|
# well, this one is tricky. If we allow HTTP/3, and remote host was marked as QUIC capable
|
||||||
# but is not anymore, we may face an indefinite hang if timeout isn't set. This could surprise some user.
|
# but is not anymore, we may face an indefinite hang if timeout isn't set. This could surprise some user.
|
||||||
elif (
|
elif (
|
||||||
args.disable_http3 is False
|
not args.disable_http3
|
||||||
|
and not args.force_http3
|
||||||
and requests_session.quic_cache_layer.get((parsed_url.host, parsed_url.port or 443)) is not None
|
and requests_session.quic_cache_layer.get((parsed_url.host, parsed_url.port or 443)) is not None
|
||||||
and args.force_http3 is False
|
|
||||||
):
|
):
|
||||||
# we only set the connect timeout, the rest is still indefinite.
|
# we only set the connect timeout, the rest is still indefinite.
|
||||||
if send_kwargs["timeout"] is None:
|
if send_kwargs["timeout"] is None:
|
||||||
|
@ -2,11 +2,12 @@ import sys
|
|||||||
from typing import Any, Optional, Iterable
|
from typing import Any, Optional, Iterable
|
||||||
|
|
||||||
from httpie.cookies import HTTPieCookiePolicy
|
from httpie.cookies import HTTPieCookiePolicy
|
||||||
from http import cookiejar # noqa
|
from http import cookiejar # noqa
|
||||||
|
|
||||||
import niquests
|
import niquests
|
||||||
from niquests._compat import HAS_LEGACY_URLLIB3
|
from niquests._compat import HAS_LEGACY_URLLIB3
|
||||||
|
|
||||||
|
|
||||||
# to understand why this is required
|
# to understand why this is required
|
||||||
# see https://niquests.readthedocs.io/en/latest/community/faq.html#what-is-urllib3-future
|
# see https://niquests.readthedocs.io/en/latest/community/faq.html#what-is-urllib3-future
|
||||||
# short story, urllib3 (import/top-level import) may be the legacy one https://github.com/urllib3/urllib3
|
# short story, urllib3 (import/top-level import) may be the legacy one https://github.com/urllib3/urllib3
|
||||||
@ -31,6 +32,25 @@ else:
|
|||||||
resolve_ssl_version,
|
resolve_ssl_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Importlib_metadata was a provisional module, so the APIs changed quite a few times
|
||||||
|
# between 3.8-3.10. It was also not included in the standard library until 3.8, so
|
||||||
|
# we install the backport for <3.8.
|
||||||
|
if sys.version_info >= (3, 8):
|
||||||
|
import importlib.metadata as importlib_metadata
|
||||||
|
else:
|
||||||
|
import importlib_metadata
|
||||||
|
|
||||||
|
is_windows = 'win32' in str(sys.platform).lower()
|
||||||
|
is_frozen = getattr(sys, 'frozen', False)
|
||||||
|
|
||||||
|
MIN_SUPPORTED_PY_VERSION = (3, 7)
|
||||||
|
MAX_SUPPORTED_PY_VERSION = (3, 11)
|
||||||
|
|
||||||
|
# Request does not carry the original policy attached to the
|
||||||
|
# cookie jar, so until it is resolved we change the global cookie
|
||||||
|
# policy. <https://github.com/psf/requests/issues/5449>
|
||||||
|
cookiejar.DefaultCookiePolicy = HTTPieCookiePolicy
|
||||||
|
|
||||||
|
|
||||||
def has_ipv6_support(new_value: Optional[bool] = None) -> bool:
|
def has_ipv6_support(new_value: Optional[bool] = None) -> bool:
|
||||||
if new_value is not None:
|
if new_value is not None:
|
||||||
@ -52,17 +72,6 @@ def enforce_niquests():
|
|||||||
sys.modules["requests.exceptions"] = niquests.exceptions
|
sys.modules["requests.exceptions"] = niquests.exceptions
|
||||||
sys.modules["requests.packages.urllib3"] = urllib3
|
sys.modules["requests.packages.urllib3"] = urllib3
|
||||||
|
|
||||||
# Request does not carry the original policy attached to the
|
|
||||||
# cookie jar, so until it is resolved we change the global cookie
|
|
||||||
# policy. <https://github.com/psf/requests/issues/5449>
|
|
||||||
cookiejar.DefaultCookiePolicy = HTTPieCookiePolicy
|
|
||||||
|
|
||||||
|
|
||||||
is_windows = 'win32' in str(sys.platform).lower()
|
|
||||||
is_frozen = getattr(sys, 'frozen', False)
|
|
||||||
|
|
||||||
MIN_SUPPORTED_PY_VERSION = (3, 7)
|
|
||||||
MAX_SUPPORTED_PY_VERSION = (3, 11)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
@ -114,16 +123,6 @@ except ImportError:
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
# importlib_metadata was a provisional module, so the APIs changed quite a few times
|
|
||||||
# between 3.8-3.10. It was also not included in the standard library until 3.8, so
|
|
||||||
# we install the backport for <3.8.
|
|
||||||
|
|
||||||
if sys.version_info >= (3, 8):
|
|
||||||
import importlib.metadata as importlib_metadata
|
|
||||||
else:
|
|
||||||
import importlib_metadata
|
|
||||||
|
|
||||||
|
|
||||||
def find_entry_points(entry_points: Any, group: str) -> Iterable[importlib_metadata.EntryPoint]:
|
def find_entry_points(entry_points: Any, group: str) -> Iterable[importlib_metadata.EntryPoint]:
|
||||||
if hasattr(entry_points, "select"): # Python 3.10+ / importlib_metadata >= 3.9.0
|
if hasattr(entry_points, "select"): # Python 3.10+ / importlib_metadata >= 3.9.0
|
||||||
return entry_points.select(group=group)
|
return entry_points.select(group=group)
|
||||||
|
@ -45,15 +45,15 @@ def test_non_existent_interface_arg(httpbin):
|
|||||||
('-0-8000', (0, 8000)),
|
('-0-8000', (0, 8000)),
|
||||||
('0-0', (0, 0)),
|
('0-0', (0, 0)),
|
||||||
# Port ranges — invalid
|
# Port ranges — invalid
|
||||||
(f'2-1', 'not a valid port range'),
|
('2-1', 'not a valid port range'),
|
||||||
(f'2-', 'not a number'),
|
('2-', 'not a number'),
|
||||||
(f'2-A', 'not a number'),
|
('2-A', 'not a number'),
|
||||||
(f'A-A', 'not a number'),
|
('A-A', 'not a number'),
|
||||||
(f'A-2', 'not a number'),
|
('A-2', 'not a number'),
|
||||||
(f'-10-1', OUTSIDE_VALID_PORT_RANGE_ERROR),
|
('-10-1', OUTSIDE_VALID_PORT_RANGE_ERROR),
|
||||||
(f'1--1', OUTSIDE_VALID_PORT_RANGE_ERROR),
|
('1--1', OUTSIDE_VALID_PORT_RANGE_ERROR),
|
||||||
(f'-10--1', OUTSIDE_VALID_PORT_RANGE_ERROR),
|
('-10--1', OUTSIDE_VALID_PORT_RANGE_ERROR),
|
||||||
(f'1-{MAX_PORT + 1}', OUTSIDE_VALID_PORT_RANGE_ERROR),
|
('1-{MAX_PORT + 1}', OUTSIDE_VALID_PORT_RANGE_ERROR),
|
||||||
])
|
])
|
||||||
def test_parse_local_port_arg(local_port_arg, expected_output):
|
def test_parse_local_port_arg(local_port_arg, expected_output):
|
||||||
expected_error = expected_output if isinstance(expected_output, str) else None
|
expected_error = expected_output if isinstance(expected_output, str) else None
|
||||||
|
Loading…
Reference in New Issue
Block a user