mirror of
https://github.com/httpie/cli.git
synced 2025-03-13 06:18:33 +01:00
Refactor niquests
enforcement to compat.enforce_niquests()
This commit is contained in:
parent
a367a55173
commit
0eab08a655
@ -4,6 +4,7 @@ from typing import Any, Optional, Iterable
|
||||
from httpie.cookies import HTTPieCookiePolicy
|
||||
from http import cookiejar # noqa
|
||||
|
||||
import niquests
|
||||
from niquests._compat import HAS_LEGACY_URLLIB3
|
||||
|
||||
# to understand why this is required
|
||||
@ -30,6 +31,19 @@ else:
|
||||
resolve_ssl_version,
|
||||
)
|
||||
|
||||
def enforce_niquests():
|
||||
"""
|
||||
Force imported 3rd-party plugins to use `niquests` instead of `requests` if they haven’t migrated yet.
|
||||
|
||||
It’s a drop-in replacement for Requests so such plugins might continue to work unless they touch internals.
|
||||
|
||||
"""
|
||||
sys.modules["requests"] = niquests
|
||||
sys.modules["requests.adapters"] = niquests.adapters
|
||||
sys.modules["requests.sessions"] = niquests.sessions
|
||||
sys.modules["requests.exceptions"] = niquests.exceptions
|
||||
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>
|
||||
|
@ -1,29 +1,16 @@
|
||||
import sys
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
from contextlib import contextmanager, nullcontext
|
||||
from itertools import groupby
|
||||
from operator import attrgetter
|
||||
from typing import Dict, List, Type, Iterator, Iterable, Optional, ContextManager
|
||||
from pathlib import Path
|
||||
from contextlib import contextmanager, nullcontext
|
||||
from typing import Dict, List, Type, Iterator, Iterable, Optional, ContextManager
|
||||
|
||||
import niquests
|
||||
|
||||
from ..compat import importlib_metadata, find_entry_points, get_dist_name, urllib3
|
||||
|
||||
from ..utils import repr_dict, get_site_paths
|
||||
from . import AuthPlugin, ConverterPlugin, FormatterPlugin, TransportPlugin
|
||||
from .base import BasePlugin
|
||||
|
||||
# make sure all the plugins are forced to migrate to Niquests
|
||||
# as it is a drop in replacement for Requests, everything should
|
||||
# run smooth.
|
||||
sys.modules["requests"] = niquests
|
||||
sys.modules["requests.adapters"] = niquests.adapters
|
||||
sys.modules["requests.sessions"] = niquests.sessions
|
||||
sys.modules["requests.exceptions"] = niquests.exceptions
|
||||
sys.modules["requests.packages.urllib3"] = urllib3
|
||||
from ..compat import importlib_metadata, find_entry_points, get_dist_name, enforce_niquests
|
||||
from ..utils import repr_dict, get_site_paths
|
||||
|
||||
|
||||
ENTRY_POINT_CLASSES = {
|
||||
@ -75,6 +62,7 @@ class PluginManager(list):
|
||||
yield from find_entry_points(eps, group=entry_point_name)
|
||||
|
||||
def load_installed_plugins(self, directory: Optional[Path] = None):
|
||||
enforce_niquests()
|
||||
for entry_point in self.iter_entry_points(directory):
|
||||
plugin_name = get_dist_name(entry_point)
|
||||
try:
|
||||
@ -83,8 +71,8 @@ class PluginManager(list):
|
||||
warnings.warn(
|
||||
f'While loading "{plugin_name}", an error occurred: {exc}\n'
|
||||
f'For uninstallations, please use either "httpie plugins uninstall {plugin_name}" '
|
||||
f'or "pip uninstall {plugin_name}" (depending on how you installed it in the first '
|
||||
'place).'
|
||||
f'or "pip uninstall {plugin_name}" (depending on how you installed it in the first place). '
|
||||
'The error might be related to HTTPie’s migration from `requests` to `niquests`.'
|
||||
)
|
||||
continue
|
||||
plugin.package_name = plugin_name
|
||||
|
Loading…
Reference in New Issue
Block a user