From: Florimond Manca Date: Tue, 28 Jan 2020 14:34:43 +0000 (+0100) Subject: Switch to private module names (#785) X-Git-Tag: 0.12.0~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82dc6f32f864d26677df8fc61249a7fc74c687e8;p=thirdparty%2Fhttpx.git Switch to private module names (#785) * Rename modules * Update names in package * Fix tests * Review docs --- diff --git a/docs/environment_variables.md b/docs/environment_variables.md index 123a8908..4f74e490 100644 --- a/docs/environment_variables.md +++ b/docs/environment_variables.md @@ -32,46 +32,46 @@ Debug output: ```console $ HTTPX_LOG_LEVEL=debug python test_script.py -DEBUG [2019-11-06 19:11:24] httpx.client - HTTP Request: GET https://google.com "HTTP/1.1 301 Moved Permanently" -DEBUG [2019-11-06 19:11:24] httpx.client - HTTP Request: GET https://www.google.com/ "HTTP/1.1 200 OK" +DEBUG [2019-11-06 19:11:24] httpx._client - HTTP Request: GET https://google.com "HTTP/1.1 301 Moved Permanently" +DEBUG [2019-11-06 19:11:24] httpx._client - HTTP Request: GET https://www.google.com/ "HTTP/1.1 200 OK" ``` Trace output: ```console $ HTTPX_LOG_LEVEL=trace python test_script.py -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='google.com' port=443) -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='google.com' port=443)) -TRACE [2019-11-06 19:18:56] httpx.config - load_ssl_context verify=True cert=None trust_env=True http_versions=HTTPVersionConfig(['HTTP/1.1', 'HTTP/2']) -TRACE [2019-11-06 19:18:56] httpx.config - load_verify_locations cafile=/Users/florimond/Developer/python-projects/httpx/venv/lib/python3.8/site-packages/certifi/cacert.pem -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - start_connect host='google.com' port=443 timeout=Timeout(timeout=5.0) -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - connected http_version='HTTP/2' -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - send_headers stream_id=1 method='GET' target='/' headers=[(b':method', b'GET'), (b':authority', b'google.com'), (b':scheme', b'https'), (b':path', b'/'), (b'user-agent', b'python-httpx/0.7.6'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate, br'), (b'connection', b'keep-alive')] -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - end_stream stream_id=1 -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event= -DEBUG [2019-11-06 19:18:56] httpx.client - HTTP Request: GET https://google.com "HTTP/2 301 Moved Permanently" -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='www.google.com' port=443) -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443)) -TRACE [2019-11-06 19:18:56] httpx.config - load_ssl_context verify=True cert=None trust_env=True http_versions=HTTPVersionConfig(['HTTP/1.1', 'HTTP/2']) -TRACE [2019-11-06 19:18:56] httpx.config - load_verify_locations cafile=/Users/florimond/Developer/python-projects/httpx/venv/lib/python3.8/site-packages/certifi/cacert.pem -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - start_connect host='www.google.com' port=443 timeout=Timeout(timeout=5.0) -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - connected http_version='HTTP/2' -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - send_headers stream_id=1 method='GET' target='/' headers=[(b':method', b'GET'), (b':authority', b'www.google.com'), (b':scheme', b'https'), (b':path', b'/'), (b'user-agent', b'python-httpx/0.7.6'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate, br'), (b'connection', b'keep-alive')] -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - end_stream stream_id=1 -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event= -DEBUG [2019-11-06 19:18:56] httpx.client - HTTP Request: GET https://www.google.com/ "HTTP/2 200 OK" -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=1 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.http2 - receive_event stream_id=0 event= -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection_pool - release_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443)) -TRACE [2019-11-06 19:18:56] httpx.dispatch.connection - close_connection +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='google.com' port=443) +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='google.com' port=443)) +TRACE [2019-11-06 19:18:56] httpx._config - load_ssl_context verify=True cert=None trust_env=True http_versions=HTTPVersionConfig(['HTTP/1.1', 'HTTP/2']) +TRACE [2019-11-06 19:18:56] httpx._config - load_verify_locations cafile=/Users/florimond/Developer/python-projects/httpx/venv/lib/python3.8/site-packages/certifi/cacert.pem +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection - start_connect host='google.com' port=443 timeout=Timeout(timeout=5.0) +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection - connected http_version='HTTP/2' +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - send_headers stream_id=1 method='GET' target='/' headers=[(b':method', b'GET'), (b':authority', b'google.com'), (b':scheme', b'https'), (b':path', b'/'), (b'user-agent', b'python-httpx/0.7.6'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate, br'), (b'connection', b'keep-alive')] +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - end_stream stream_id=1 +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=0 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=0 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=0 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=1 event= +DEBUG [2019-11-06 19:18:56] httpx._client - HTTP Request: GET https://google.com "HTTP/2 301 Moved Permanently" +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection_pool - acquire_connection origin=Origin(scheme='https' host='www.google.com' port=443) +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443)) +TRACE [2019-11-06 19:18:56] httpx._config - load_ssl_context verify=True cert=None trust_env=True http_versions=HTTPVersionConfig(['HTTP/1.1', 'HTTP/2']) +TRACE [2019-11-06 19:18:56] httpx._config - load_verify_locations cafile=/Users/florimond/Developer/python-projects/httpx/venv/lib/python3.8/site-packages/certifi/cacert.pem +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection - start_connect host='www.google.com' port=443 timeout=Timeout(timeout=5.0) +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection - connected http_version='HTTP/2' +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - send_headers stream_id=1 method='GET' target='/' headers=[(b':method', b'GET'), (b':authority', b'www.google.com'), (b':scheme', b'https'), (b':path', b'/'), (b'user-agent', b'python-httpx/0.7.6'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate, br'), (b'connection', b'keep-alive')] +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - end_stream stream_id=1 +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=0 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=0 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=0 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=1 event= +DEBUG [2019-11-06 19:18:56] httpx._client - HTTP Request: GET https://www.google.com/ "HTTP/2 200 OK" +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=1 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=1 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=1 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.http2 - receive_event stream_id=0 event= +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection_pool - release_connection connection=HTTPConnection(origin=Origin(scheme='https' host='www.google.com' port=443)) +TRACE [2019-11-06 19:18:56] httpx._dispatch.connection - close_connection ``` `SSLKEYLOGFILE` diff --git a/httpx/__init__.py b/httpx/__init__.py index 4a133e8e..55f8526c 100644 --- a/httpx/__init__.py +++ b/httpx/__init__.py @@ -1,11 +1,11 @@ from .__version__ import __description__, __title__, __version__ -from .api import delete, get, head, options, patch, post, put, request, stream -from .auth import Auth, BasicAuth, DigestAuth -from .client import AsyncClient, Client -from .config import PoolLimits, Proxy, Timeout -from .dispatch.asgi import ASGIDispatch -from .dispatch.wsgi import WSGIDispatch -from .exceptions import ( +from ._api import delete, get, head, options, patch, post, put, request, stream +from ._auth import Auth, BasicAuth, DigestAuth +from ._client import AsyncClient, Client +from ._config import PoolLimits, Proxy, Timeout +from ._dispatch.asgi import ASGIDispatch +from ._dispatch.wsgi import WSGIDispatch +from ._exceptions import ( ConnectionClosed, ConnectTimeout, CookieConflict, @@ -27,8 +27,8 @@ from .exceptions import ( TooManyRedirects, WriteTimeout, ) -from .models import URL, Cookies, Headers, QueryParams, Request, Response -from .status_codes import StatusCode, codes +from ._models import URL, Cookies, Headers, QueryParams, Request, Response +from ._status_codes import StatusCode, codes __all__ = [ "__description__", diff --git a/httpx/api.py b/httpx/_api.py similarity index 98% rename from httpx/api.py rename to httpx/_api.py index 7fbbd308..19ef229f 100644 --- a/httpx/api.py +++ b/httpx/_api.py @@ -1,9 +1,9 @@ import typing -from .auth import AuthTypes -from .client import Client, StreamContextManager -from .config import DEFAULT_TIMEOUT_CONFIG, CertTypes, TimeoutTypes, VerifyTypes -from .models import ( +from ._auth import AuthTypes +from ._client import Client, StreamContextManager +from ._config import DEFAULT_TIMEOUT_CONFIG, CertTypes, TimeoutTypes, VerifyTypes +from ._models import ( CookieTypes, HeaderTypes, QueryParamTypes, diff --git a/httpx/auth.py b/httpx/_auth.py similarity index 98% rename from httpx/auth.py rename to httpx/_auth.py index d38322f7..c1fa8925 100644 --- a/httpx/auth.py +++ b/httpx/_auth.py @@ -6,9 +6,9 @@ import typing from base64 import b64encode from urllib.request import parse_http_list -from .exceptions import ProtocolError, RequestBodyUnavailable -from .models import Request, Response -from .utils import to_bytes, to_str, unquote +from ._exceptions import ProtocolError, RequestBodyUnavailable +from ._models import Request, Response +from ._utils import to_bytes, to_str, unquote AuthTypes = typing.Union[ typing.Tuple[typing.Union[str, bytes], typing.Union[str, bytes]], diff --git a/httpx/backends/__init__.py b/httpx/_backends/__init__.py similarity index 100% rename from httpx/backends/__init__.py rename to httpx/_backends/__init__.py diff --git a/httpx/backends/asyncio.py b/httpx/_backends/asyncio.py similarity index 98% rename from httpx/backends/asyncio.py rename to httpx/_backends/asyncio.py index 8d102574..c576909f 100644 --- a/httpx/backends/asyncio.py +++ b/httpx/_backends/asyncio.py @@ -2,9 +2,9 @@ import asyncio import ssl import typing -from ..config import Timeout -from ..exceptions import ConnectTimeout, ReadTimeout, WriteTimeout -from ..utils import as_network_error +from .._config import Timeout +from .._exceptions import ConnectTimeout, ReadTimeout, WriteTimeout +from .._utils import as_network_error from .base import BaseLock, BaseSemaphore, BaseSocketStream, ConcurrencyBackend SSL_MONKEY_PATCH_APPLIED = False diff --git a/httpx/backends/auto.py b/httpx/_backends/auto.py similarity index 98% rename from httpx/backends/auto.py rename to httpx/_backends/auto.py index 7a8c5978..d034693b 100644 --- a/httpx/backends/auto.py +++ b/httpx/_backends/auto.py @@ -3,7 +3,7 @@ import typing import sniffio -from ..config import Timeout +from .._config import Timeout from .base import ( BaseLock, BaseSemaphore, diff --git a/httpx/backends/base.py b/httpx/_backends/base.py similarity index 99% rename from httpx/backends/base.py rename to httpx/_backends/base.py index 964d0944..88710634 100644 --- a/httpx/backends/base.py +++ b/httpx/_backends/base.py @@ -2,7 +2,7 @@ import ssl import typing from types import TracebackType -from ..config import Timeout +from .._config import Timeout def lookup_backend( diff --git a/httpx/backends/trio.py b/httpx/_backends/trio.py similarity index 97% rename from httpx/backends/trio.py rename to httpx/_backends/trio.py index 33e93e96..e89340a4 100644 --- a/httpx/backends/trio.py +++ b/httpx/_backends/trio.py @@ -3,9 +3,9 @@ import typing import trio -from ..config import Timeout -from ..exceptions import ConnectTimeout, ReadTimeout, WriteTimeout -from ..utils import as_network_error +from .._config import Timeout +from .._exceptions import ConnectTimeout, ReadTimeout, WriteTimeout +from .._utils import as_network_error from .base import BaseLock, BaseSemaphore, BaseSocketStream, ConcurrencyBackend diff --git a/httpx/client.py b/httpx/_client.py similarity index 98% rename from httpx/client.py rename to httpx/_client.py index 49914787..109c8351 100644 --- a/httpx/client.py +++ b/httpx/_client.py @@ -4,9 +4,9 @@ from types import TracebackType import hstspreload -from .auth import Auth, AuthTypes, BasicAuth, FunctionAuth -from .backends.base import ConcurrencyBackend -from .config import ( +from ._auth import Auth, AuthTypes, BasicAuth, FunctionAuth +from ._backends.base import ConcurrencyBackend +from ._config import ( DEFAULT_MAX_REDIRECTS, DEFAULT_POOL_LIMITS, DEFAULT_TIMEOUT_CONFIG, @@ -20,21 +20,21 @@ from .config import ( UnsetType, VerifyTypes, ) -from .content_streams import ContentStream -from .dispatch.asgi import ASGIDispatch -from .dispatch.base import AsyncDispatcher, SyncDispatcher -from .dispatch.connection_pool import ConnectionPool -from .dispatch.proxy_http import HTTPProxy -from .dispatch.urllib3 import URLLib3Dispatcher -from .dispatch.wsgi import WSGIDispatch -from .exceptions import ( +from ._content_streams import ContentStream +from ._dispatch.asgi import ASGIDispatch +from ._dispatch.base import AsyncDispatcher, SyncDispatcher +from ._dispatch.connection_pool import ConnectionPool +from ._dispatch.proxy_http import HTTPProxy +from ._dispatch.urllib3 import URLLib3Dispatcher +from ._dispatch.wsgi import WSGIDispatch +from ._exceptions import ( HTTPError, InvalidURL, RedirectLoop, RequestBodyUnavailable, TooManyRedirects, ) -from .models import ( +from ._models import ( URL, Cookies, CookieTypes, @@ -49,8 +49,8 @@ from .models import ( Response, URLTypes, ) -from .status_codes import codes -from .utils import NetRCInfo, get_environment_proxies, get_logger +from ._status_codes import codes +from ._utils import NetRCInfo, get_environment_proxies, get_logger logger = get_logger(__name__) diff --git a/httpx/config.py b/httpx/_config.py similarity index 99% rename from httpx/config.py rename to httpx/_config.py index 64c3c330..1531e2e8 100644 --- a/httpx/config.py +++ b/httpx/_config.py @@ -6,8 +6,8 @@ from pathlib import Path import certifi -from .models import URL, Headers, HeaderTypes, URLTypes -from .utils import get_ca_bundle_from_env, get_logger +from ._models import URL, Headers, HeaderTypes, URLTypes +from ._utils import get_ca_bundle_from_env, get_logger CertTypes = typing.Union[str, typing.Tuple[str, str], typing.Tuple[str, str, str]] VerifyTypes = typing.Union[str, bool, ssl.SSLContext] diff --git a/httpx/content_streams.py b/httpx/_content_streams.py similarity index 99% rename from httpx/content_streams.py rename to httpx/_content_streams.py index e3e343cf..ca483268 100644 --- a/httpx/content_streams.py +++ b/httpx/_content_streams.py @@ -7,8 +7,8 @@ from json import dumps as json_dumps from pathlib import Path from urllib.parse import urlencode -from .exceptions import StreamConsumed -from .utils import format_form_param +from ._exceptions import StreamConsumed +from ._utils import format_form_param RequestData = typing.Union[ dict, str, bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes] diff --git a/httpx/decoders.py b/httpx/_decoders.py similarity index 99% rename from httpx/decoders.py rename to httpx/_decoders.py index 454ec4a1..cecd65da 100644 --- a/httpx/decoders.py +++ b/httpx/_decoders.py @@ -9,7 +9,7 @@ import zlib import chardet -from .exceptions import DecodingError +from ._exceptions import DecodingError try: import brotli diff --git a/httpx/dispatch/__init__.py b/httpx/_dispatch/__init__.py similarity index 100% rename from httpx/dispatch/__init__.py rename to httpx/_dispatch/__init__.py diff --git a/httpx/dispatch/asgi.py b/httpx/_dispatch/asgi.py similarity index 97% rename from httpx/dispatch/asgi.py rename to httpx/_dispatch/asgi.py index a0b55e2b..d15dfb8c 100644 --- a/httpx/dispatch/asgi.py +++ b/httpx/_dispatch/asgi.py @@ -1,8 +1,8 @@ import typing -from ..config import TimeoutTypes -from ..content_streams import ByteStream -from ..models import Request, Response +from .._config import TimeoutTypes +from .._content_streams import ByteStream +from .._models import Request, Response from .base import AsyncDispatcher diff --git a/httpx/dispatch/base.py b/httpx/_dispatch/base.py similarity index 96% rename from httpx/dispatch/base.py rename to httpx/_dispatch/base.py index ae25e4db..26defd19 100644 --- a/httpx/dispatch/base.py +++ b/httpx/_dispatch/base.py @@ -1,8 +1,8 @@ import typing from types import TracebackType -from ..config import Timeout -from ..models import ( +from .._config import Timeout +from .._models import ( HeaderTypes, QueryParamTypes, Request, diff --git a/httpx/dispatch/connection.py b/httpx/_dispatch/connection.py similarity index 96% rename from httpx/dispatch/connection.py rename to httpx/_dispatch/connection.py index 9b6b28b7..5d898458 100644 --- a/httpx/dispatch/connection.py +++ b/httpx/_dispatch/connection.py @@ -3,10 +3,10 @@ import typing import h11 -from ..backends.base import ConcurrencyBackend, lookup_backend -from ..config import SSLConfig, Timeout -from ..models import URL, Origin, Request, Response -from ..utils import get_logger +from .._backends.base import ConcurrencyBackend, lookup_backend +from .._config import SSLConfig, Timeout +from .._models import URL, Origin, Request, Response +from .._utils import get_logger from .base import AsyncDispatcher from .http2 import HTTP2Connection from .http11 import HTTP11Connection diff --git a/httpx/dispatch/connection_pool.py b/httpx/_dispatch/connection_pool.py similarity index 97% rename from httpx/dispatch/connection_pool.py rename to httpx/_dispatch/connection_pool.py index eb2a11a5..61d323c5 100644 --- a/httpx/dispatch/connection_pool.py +++ b/httpx/_dispatch/connection_pool.py @@ -1,7 +1,7 @@ import typing -from ..backends.base import BaseSemaphore, ConcurrencyBackend, lookup_backend -from ..config import ( +from .._backends.base import BaseSemaphore, ConcurrencyBackend, lookup_backend +from .._config import ( DEFAULT_POOL_LIMITS, CertTypes, PoolLimits, @@ -9,9 +9,9 @@ from ..config import ( Timeout, VerifyTypes, ) -from ..exceptions import PoolTimeout -from ..models import Origin, Request, Response -from ..utils import get_logger +from .._exceptions import PoolTimeout +from .._models import Origin, Request, Response +from .._utils import get_logger from .base import AsyncDispatcher from .connection import HTTPConnection diff --git a/httpx/dispatch/http11.py b/httpx/_dispatch/http11.py similarity index 96% rename from httpx/dispatch/http11.py rename to httpx/_dispatch/http11.py index 2ed33845..fce98827 100644 --- a/httpx/dispatch/http11.py +++ b/httpx/_dispatch/http11.py @@ -2,12 +2,12 @@ import typing import h11 -from ..backends.base import BaseSocketStream -from ..config import Timeout -from ..content_streams import AsyncIteratorStream -from ..exceptions import ConnectionClosed, ProtocolError -from ..models import Request, Response -from ..utils import get_logger +from .._backends.base import BaseSocketStream +from .._config import Timeout +from .._content_streams import AsyncIteratorStream +from .._exceptions import ConnectionClosed, ProtocolError +from .._models import Request, Response +from .._utils import get_logger H11Event = typing.Union[ h11.Request, diff --git a/httpx/dispatch/http2.py b/httpx/_dispatch/http2.py similarity index 97% rename from httpx/dispatch/http2.py rename to httpx/_dispatch/http2.py index a85d46b6..d5724de5 100644 --- a/httpx/dispatch/http2.py +++ b/httpx/_dispatch/http2.py @@ -5,17 +5,17 @@ import h2.events from h2.config import H2Configuration from h2.settings import SettingCodes, Settings -from ..backends.base import ( +from .._backends.base import ( BaseLock, BaseSocketStream, ConcurrencyBackend, lookup_backend, ) -from ..config import Timeout -from ..content_streams import AsyncIteratorStream -from ..exceptions import ProtocolError -from ..models import Request, Response -from ..utils import get_logger +from .._config import Timeout +from .._content_streams import AsyncIteratorStream +from .._exceptions import ProtocolError +from .._models import Request, Response +from .._utils import get_logger logger = get_logger(__name__) diff --git a/httpx/dispatch/proxy_http.py b/httpx/_dispatch/proxy_http.py similarity index 96% rename from httpx/dispatch/proxy_http.py rename to httpx/_dispatch/proxy_http.py index 743e04d3..73cea2ba 100644 --- a/httpx/dispatch/proxy_http.py +++ b/httpx/_dispatch/proxy_http.py @@ -3,8 +3,8 @@ import typing import warnings from base64 import b64encode -from ..backends.base import ConcurrencyBackend -from ..config import ( +from .._backends.base import ConcurrencyBackend +from .._config import ( DEFAULT_POOL_LIMITS, CertTypes, PoolLimits, @@ -12,9 +12,9 @@ from ..config import ( Timeout, VerifyTypes, ) -from ..exceptions import ProxyError -from ..models import URL, Headers, HeaderTypes, Origin, Request, Response, URLTypes -from ..utils import get_logger +from .._exceptions import ProxyError +from .._models import URL, Headers, HeaderTypes, Origin, Request, Response, URLTypes +from .._utils import get_logger from .connection import HTTPConnection from .connection_pool import ConnectionPool diff --git a/httpx/dispatch/urllib3.py b/httpx/_dispatch/urllib3.py similarity index 96% rename from httpx/dispatch/urllib3.py rename to httpx/_dispatch/urllib3.py index 2728170c..bde2952f 100644 --- a/httpx/dispatch/urllib3.py +++ b/httpx/_dispatch/urllib3.py @@ -6,7 +6,7 @@ import typing import urllib3 from urllib3.exceptions import MaxRetryError, SSLError -from ..config import ( +from .._config import ( DEFAULT_POOL_LIMITS, CertTypes, PoolLimits, @@ -15,9 +15,9 @@ from ..config import ( Timeout, VerifyTypes, ) -from ..content_streams import IteratorStream -from ..models import Request, Response -from ..utils import as_network_error +from .._content_streams import IteratorStream +from .._models import Request, Response +from .._utils import as_network_error from .base import SyncDispatcher diff --git a/httpx/dispatch/wsgi.py b/httpx/_dispatch/wsgi.py similarity index 96% rename from httpx/dispatch/wsgi.py rename to httpx/_dispatch/wsgi.py index 2a90187c..60540a8b 100644 --- a/httpx/dispatch/wsgi.py +++ b/httpx/_dispatch/wsgi.py @@ -1,9 +1,9 @@ import io import typing -from ..config import TimeoutTypes -from ..content_streams import IteratorStream -from ..models import Request, Response +from .._config import TimeoutTypes +from .._content_streams import IteratorStream +from .._models import Request, Response from .base import SyncDispatcher diff --git a/httpx/exceptions.py b/httpx/_exceptions.py similarity index 97% rename from httpx/exceptions.py rename to httpx/_exceptions.py index 7efe6fb3..562c2ed6 100644 --- a/httpx/exceptions.py +++ b/httpx/_exceptions.py @@ -1,7 +1,7 @@ import typing if typing.TYPE_CHECKING: - from .models import Request, Response # pragma: nocover + from ._models import Request, Response # pragma: nocover class HTTPError(Exception): diff --git a/httpx/models.py b/httpx/_models.py similarity index 99% rename from httpx/models.py rename to httpx/_models.py index 8d22738b..861e85fa 100644 --- a/httpx/models.py +++ b/httpx/_models.py @@ -13,14 +13,14 @@ import chardet import rfc3986 from .__version__ import __version__ -from .content_streams import ( +from ._content_streams import ( ByteStream, ContentStream, RequestData, RequestFiles, encode, ) -from .decoders import ( +from ._decoders import ( SUPPORTED_DECODERS, Decoder, IdentityDecoder, @@ -28,7 +28,7 @@ from .decoders import ( MultiDecoder, TextDecoder, ) -from .exceptions import ( +from ._exceptions import ( CookieConflict, HTTPError, InvalidURL, @@ -38,8 +38,8 @@ from .exceptions import ( ResponseNotRead, StreamConsumed, ) -from .status_codes import StatusCode -from .utils import ( +from ._status_codes import StatusCode +from ._utils import ( ElapsedTimer, flatten_queryparams, guess_json_utf, @@ -52,7 +52,7 @@ from .utils import ( ) if typing.TYPE_CHECKING: # pragma: no cover - from .dispatch.base import AsyncDispatcher # noqa: F401 + from ._dispatch.base import AsyncDispatcher # noqa: F401 PrimitiveData = typing.Optional[typing.Union[str, int, float, bool]] diff --git a/httpx/status_codes.py b/httpx/_status_codes.py similarity index 100% rename from httpx/status_codes.py rename to httpx/_status_codes.py diff --git a/httpx/utils.py b/httpx/_utils.py similarity index 99% rename from httpx/utils.py rename to httpx/_utils.py index 5700a1cc..b884f819 100644 --- a/httpx/utils.py +++ b/httpx/_utils.py @@ -13,11 +13,11 @@ from time import perf_counter from types import TracebackType from urllib.request import getproxies -from .exceptions import NetworkError +from ._exceptions import NetworkError if typing.TYPE_CHECKING: # pragma: no cover - from .models import PrimitiveData - from .models import URL + from ._models import PrimitiveData + from ._models import URL _HTML5_FORM_ENCODING_REPLACEMENTS = {'"': "%22", "\\": "\\\\"} diff --git a/tests/client/test_auth.py b/tests/client/test_auth.py index 8449b941..10bdb871 100644 --- a/tests/client/test_auth.py +++ b/tests/client/test_auth.py @@ -15,8 +15,8 @@ from httpx import ( RequestBodyUnavailable, Response, ) -from httpx.config import CertTypes, TimeoutTypes, VerifyTypes -from httpx.dispatch.base import AsyncDispatcher +from httpx._config import CertTypes, TimeoutTypes, VerifyTypes +from httpx._dispatch.base import AsyncDispatcher class MockDispatch(AsyncDispatcher): diff --git a/tests/client/test_cookies.py b/tests/client/test_cookies.py index 2932232d..f5bb21fe 100644 --- a/tests/client/test_cookies.py +++ b/tests/client/test_cookies.py @@ -4,8 +4,8 @@ from http.cookiejar import Cookie, CookieJar import pytest from httpx import AsyncClient, Cookies, Request, Response -from httpx.config import CertTypes, TimeoutTypes, VerifyTypes -from httpx.dispatch.base import AsyncDispatcher +from httpx._config import CertTypes, TimeoutTypes, VerifyTypes +from httpx._dispatch.base import AsyncDispatcher class MockDispatch(AsyncDispatcher): diff --git a/tests/client/test_headers.py b/tests/client/test_headers.py index 56cf24c7..22b0ba1e 100755 --- a/tests/client/test_headers.py +++ b/tests/client/test_headers.py @@ -5,8 +5,8 @@ import json import pytest from httpx import AsyncClient, Headers, Request, Response, __version__ -from httpx.config import CertTypes, TimeoutTypes, VerifyTypes -from httpx.dispatch.base import AsyncDispatcher +from httpx._config import CertTypes, TimeoutTypes, VerifyTypes +from httpx._dispatch.base import AsyncDispatcher class MockDispatch(AsyncDispatcher): diff --git a/tests/client/test_queryparams.py b/tests/client/test_queryparams.py index e0ce45b2..1c029f39 100644 --- a/tests/client/test_queryparams.py +++ b/tests/client/test_queryparams.py @@ -3,8 +3,8 @@ import json import pytest from httpx import URL, AsyncClient, QueryParams, Request, Response -from httpx.config import CertTypes, TimeoutTypes, VerifyTypes -from httpx.dispatch.base import AsyncDispatcher +from httpx._config import CertTypes, TimeoutTypes, VerifyTypes +from httpx._dispatch.base import AsyncDispatcher class MockDispatch(AsyncDispatcher): diff --git a/tests/client/test_redirects.py b/tests/client/test_redirects.py index 1717d782..ad138e52 100644 --- a/tests/client/test_redirects.py +++ b/tests/client/test_redirects.py @@ -14,9 +14,9 @@ from httpx import ( TooManyRedirects, codes, ) -from httpx.config import CertTypes, TimeoutTypes, VerifyTypes -from httpx.content_streams import AsyncIteratorStream -from httpx.dispatch.base import AsyncDispatcher +from httpx._config import CertTypes, TimeoutTypes, VerifyTypes +from httpx._content_streams import AsyncIteratorStream +from httpx._dispatch.base import AsyncDispatcher class MockDispatch(AsyncDispatcher): diff --git a/tests/dispatch/test_connection_pools.py b/tests/dispatch/test_connection_pools.py index 55c16099..7c656cfd 100644 --- a/tests/dispatch/test_connection_pools.py +++ b/tests/dispatch/test_connection_pools.py @@ -1,7 +1,7 @@ import pytest import httpx -from httpx.dispatch.connection_pool import ConnectionPool +from httpx._dispatch.connection_pool import ConnectionPool @pytest.mark.usefixtures("async_environment") diff --git a/tests/dispatch/test_connections.py b/tests/dispatch/test_connections.py index 80dd6a46..8668c28a 100644 --- a/tests/dispatch/test_connections.py +++ b/tests/dispatch/test_connections.py @@ -1,8 +1,8 @@ import pytest import httpx -from httpx.config import SSLConfig -from httpx.dispatch.connection import HTTPConnection +from httpx._config import SSLConfig +from httpx._dispatch.connection import HTTPConnection @pytest.mark.usefixtures("async_environment") diff --git a/tests/dispatch/test_proxy_http.py b/tests/dispatch/test_proxy_http.py index bdb4d6bf..60c326a2 100644 --- a/tests/dispatch/test_proxy_http.py +++ b/tests/dispatch/test_proxy_http.py @@ -1,7 +1,7 @@ import pytest import httpx -from httpx.dispatch.proxy_http import HTTPProxy +from httpx._dispatch.proxy_http import HTTPProxy from .utils import MockRawSocketBackend diff --git a/tests/dispatch/utils.py b/tests/dispatch/utils.py index 5f92cd82..9939d6d2 100644 --- a/tests/dispatch/utils.py +++ b/tests/dispatch/utils.py @@ -6,7 +6,7 @@ import h2.connection import h2.events from httpx import Request, Timeout -from httpx.backends.base import BaseSocketStream, lookup_backend +from httpx._backends.base import BaseSocketStream, lookup_backend class MockHTTP2Backend: diff --git a/tests/models/test_responses.py b/tests/models/test_responses.py index 80cbfb08..1935aba3 100644 --- a/tests/models/test_responses.py +++ b/tests/models/test_responses.py @@ -5,7 +5,7 @@ from unittest import mock import pytest import httpx -from httpx.content_streams import AsyncIteratorStream, IteratorStream +from httpx._content_streams import AsyncIteratorStream, IteratorStream REQUEST = httpx.Request("GET", "https://example.org") @@ -369,7 +369,7 @@ def test_json_without_specified_encoding_decode_error(): content = json.dumps(data).encode("utf-32-be") headers = {"Content-Type": "application/json"} # force incorrect guess from `guess_json_utf` to trigger error - with mock.patch("httpx.models.guess_json_utf", return_value="utf-32"): + with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"): response = httpx.Response( 200, content=content, headers=headers, request=REQUEST ) diff --git a/tests/models/test_url.py b/tests/models/test_url.py index 4be287d9..cb2f3ee1 100644 --- a/tests/models/test_url.py +++ b/tests/models/test_url.py @@ -1,7 +1,7 @@ import pytest from httpx import URL, InvalidURL -from httpx.models import Origin +from httpx._models import Origin @pytest.mark.parametrize( diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 3ed75520..f0045d05 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -4,10 +4,10 @@ import pytest import trio from httpx import Timeout -from httpx.backends.asyncio import AsyncioBackend -from httpx.backends.base import lookup_backend -from httpx.backends.trio import TrioBackend -from httpx.config import SSLConfig +from httpx._backends.asyncio import AsyncioBackend +from httpx._backends.base import lookup_backend +from httpx._backends.trio import TrioBackend +from httpx._config import SSLConfig from tests.concurrency import get_cipher, run_concurrently diff --git a/tests/test_config.py b/tests/test_config.py index 8507c710..f0ecf317 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -8,7 +8,7 @@ import certifi import pytest import httpx -from httpx.config import SSLConfig +from httpx._config import SSLConfig def test_load_ssl_config(): diff --git a/tests/test_content_streams.py b/tests/test_content_streams.py index 93baf8e7..6aa91f40 100644 --- a/tests/test_content_streams.py +++ b/tests/test_content_streams.py @@ -2,8 +2,8 @@ import io import pytest -from httpx.content_streams import ContentStream, encode -from httpx.exceptions import StreamConsumed +from httpx import StreamConsumed +from httpx._content_streams import ContentStream, encode @pytest.mark.asyncio diff --git a/tests/test_decoders.py b/tests/test_decoders.py index d9e82f70..9f2fa510 100644 --- a/tests/test_decoders.py +++ b/tests/test_decoders.py @@ -4,8 +4,8 @@ import brotli import pytest import httpx -from httpx.content_streams import AsyncIteratorStream -from httpx.decoders import ( +from httpx._content_streams import AsyncIteratorStream +from httpx._decoders import ( BrotliDecoder, DeflateDecoder, GZipDecoder, diff --git a/tests/test_multipart.py b/tests/test_multipart.py index e0bd750c..a08ada80 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -7,10 +7,10 @@ from unittest import mock import pytest import httpx -from httpx.config import CertTypes, TimeoutTypes, VerifyTypes -from httpx.content_streams import encode -from httpx.dispatch.base import AsyncDispatcher -from httpx.utils import format_form_param +from httpx._config import CertTypes, TimeoutTypes, VerifyTypes +from httpx._content_streams import encode +from httpx._dispatch.base import AsyncDispatcher +from httpx._utils import format_form_param class MockDispatch(AsyncDispatcher): diff --git a/tests/test_utils.py b/tests/test_utils.py index c0628016..e6d03555 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,7 +4,7 @@ import os import pytest import httpx -from httpx.utils import ( +from httpx._utils import ( ElapsedTimer, NetRCInfo, get_ca_bundle_from_env, @@ -98,7 +98,7 @@ async def test_logs_debug(server, capsys): assert response.status_code == 200 stderr = capsys.readouterr().err assert 'HTTP Request: GET http://127.0.0.1:8000/ "HTTP/1.1 200 OK"' in stderr - assert "httpx.dispatch.connection_pool" not in stderr + assert "httpx._dispatch.connection_pool" not in stderr @pytest.mark.asyncio @@ -109,7 +109,7 @@ async def test_logs_trace(server, capsys): assert response.status_code == 200 stderr = capsys.readouterr().err assert 'HTTP Request: GET http://127.0.0.1:8000/ "HTTP/1.1 200 OK"' in stderr - assert "httpx.dispatch.connection_pool" in stderr + assert "httpx._dispatch.connection_pool" in stderr @pytest.mark.asyncio @@ -283,5 +283,5 @@ def test_obfuscate_sensitive_headers(headers, output): ) def test_should_not_be_proxied(url, no_proxy, expected): os.environ.update(no_proxy) - parsed_url = httpx.models.URL(url) + parsed_url = httpx.URL(url) assert should_not_be_proxied(parsed_url) == expected diff --git a/tests/utils.py b/tests/utils.py index 50840227..e2636a53 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -2,7 +2,7 @@ import contextlib import logging import os -from httpx import utils +from httpx import _utils @contextlib.contextmanager @@ -10,8 +10,8 @@ def override_log_level(log_level: str): os.environ["HTTPX_LOG_LEVEL"] = log_level # Force a reload on the logging handlers - utils._LOGGER_INITIALIZED = False - utils.get_logger("httpx") + _utils._LOGGER_INITIALIZED = False + _utils.get_logger("httpx") try: yield