diff --git a/.gitignore b/.gitignore index 3c8632c3..6d553717 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Project-specific generated files docs/build/ -src/hip/_sync/ +src/hip/ test/with_dummyserver/sync/ bench/results/ diff --git a/.travis.yml b/.travis.yml index 071b8a82..1c511fee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,4 +62,4 @@ stages: # Deploy on any tags - name: deploy - if: tag IS present AND tag =~ /^(\d+\.\d+(?:.\d+)?)$/ AND repo = hip/hip + if: tag IS present AND tag =~ /^(\d+\.\d+(?:.\d+)?)$/ AND repo = python-trio/hip diff --git a/demo/async-demo.py b/demo/async-demo.py index aaed87a3..373e9edf 100644 --- a/demo/async-demo.py +++ b/demo/async-demo.py @@ -1,12 +1,11 @@ # This should work on python 3.6+ -import hip -from hip.backends import Backend +import ahip URL = "http://httpbin.org/uuid" async def main(backend=None): - with hip.AsyncPoolManager(backend=backend) as http: + with ahip.PoolManager(backend=backend) as http: print("URL:", URL) r = await http.request("GET", URL, preload_content=False) print("Status:", r.status) diff --git a/noxfile.py b/noxfile.py index ce43712c..4d3d95b6 100644 --- a/noxfile.py +++ b/noxfile.py @@ -43,7 +43,7 @@ def tests_impl(session, extras="socks,brotli"): "test/with_dummyserver/async", "test/with_dummyserver/sync", additional_replacements={ - "AsyncPoolManager": "PoolManager", + "ahip": "hip", "test_all_backends": "test_sync_backend", }, ) diff --git a/setup.cfg b/setup.cfg index cf7f2067..72e487c5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,7 +54,7 @@ python_classes = Test *TestCase [flake8] ignore = E501, E203, W503, W504 -exclude = ./docs/conf.py,./src/hip/packages/* +exclude = ./docs/conf.py,./src/ahip/packages/* max-line-length = 99 [bdist_wheel] diff --git a/setup.py b/setup.py index 1da76209..8b5ebea5 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,12 @@ # Get the version (borrowed from SQLAlchemy) base_path = os.path.dirname(__file__) -with open(os.path.join(base_path, "src", "hip", "__init__.py")) as fp: +with open(os.path.join(base_path, "src", "ahip", "__init__.py")) as fp: version = re.match(r".*__version__ = \"(.*?)\"", fp.read(), re.S).group(1) -setup(version=version, cmdclass={"build_py": unasync.cmdclass_build_py()}) +setup( + version=version, + cmdclass={ + "build_py": unasync.cmdclass_build_py(rules=[unasync.Rule("/ahip/", "/hip/")]) + }, +) diff --git a/src/hip/__init__.py b/src/ahip/__init__.py similarity index 75% rename from src/hip/__init__.py rename to src/ahip/__init__.py index 2a130e8c..1500f504 100644 --- a/src/hip/__init__.py +++ b/src/ahip/__init__.py @@ -40,32 +40,8 @@ "proxy_from_url", ] -# For now we only support async on 3.6, because we use async generators -import sys - -if sys.version_info >= (3, 6): - from hip._async.connectionpool import ( # NOQA - HTTPConnectionPool as AsyncHTTPConnectionPool, - HTTPSConnectionPool as AsyncHTTPSConnectionPool, - ) - from hip._async.poolmanager import ( # NOQA - PoolManager as AsyncPoolManager, - ProxyManager as AsyncProxyManager, - ) - from hip._async.response import HTTPResponse as AsyncHTTPResponse # NOQA - - __all__.extend( - ( - "AsyncHTTPConnectionPool", - "AsyncHTTPSConnectionPool", - "AsyncPoolManager", - "AsyncProxyManager", - "AsyncHTTPResponse", - ) - ) - - -logging.getLogger(__name__).addHandler(NullHandler()) + +logging.getLogger("hip").addHandler(NullHandler()) def add_stderr_logger(level=logging.DEBUG): @@ -77,12 +53,12 @@ def add_stderr_logger(level=logging.DEBUG): """ # This method needs to be in this __init__.py to get the __name__ correct # even if Hip is vendored within another package. - logger = logging.getLogger(__name__) + logger = logging.getLogger("hip") handler = logging.StreamHandler() handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s")) logger.addHandler(handler) logger.setLevel(level) - logger.debug("Added a stderr logging handler to logger: %s", __name__) + logger.debug("Added a stderr logging handler to logger: %s", "hip") return handler diff --git a/src/hip/_async/__init__.py b/src/ahip/_backends/__init__.py similarity index 100% rename from src/hip/_async/__init__.py rename to src/ahip/_backends/__init__.py diff --git a/src/hip/_backends/_common.py b/src/ahip/_backends/_common.py similarity index 100% rename from src/hip/_backends/_common.py rename to src/ahip/_backends/_common.py diff --git a/src/hip/_backends/_loader.py b/src/ahip/_backends/_loader.py similarity index 100% rename from src/hip/_backends/_loader.py rename to src/ahip/_backends/_loader.py diff --git a/src/hip/_backends/anyio_backend.py b/src/ahip/_backends/anyio_backend.py similarity index 100% rename from src/hip/_backends/anyio_backend.py rename to src/ahip/_backends/anyio_backend.py diff --git a/src/hip/_backends/async_backend.py b/src/ahip/_backends/async_backend.py similarity index 100% rename from src/hip/_backends/async_backend.py rename to src/ahip/_backends/async_backend.py diff --git a/src/hip/_backends/sync_backend.py b/src/ahip/_backends/sync_backend.py similarity index 100% rename from src/hip/_backends/sync_backend.py rename to src/ahip/_backends/sync_backend.py diff --git a/src/hip/_backends/trio_backend.py b/src/ahip/_backends/trio_backend.py similarity index 100% rename from src/hip/_backends/trio_backend.py rename to src/ahip/_backends/trio_backend.py diff --git a/src/hip/_collections.py b/src/ahip/_collections.py similarity index 100% rename from src/hip/_collections.py rename to src/ahip/_collections.py diff --git a/src/hip/backends.py b/src/ahip/backends.py similarity index 100% rename from src/hip/backends.py rename to src/ahip/backends.py diff --git a/src/hip/base.py b/src/ahip/base.py similarity index 100% rename from src/hip/base.py rename to src/ahip/base.py diff --git a/src/hip/_async/connection.py b/src/ahip/connection.py similarity index 98% rename from src/hip/_async/connection.py rename to src/ahip/connection.py index 0c3849c4..7f5d6436 100644 --- a/src/hip/_async/connection.py +++ b/src/ahip/connection.py @@ -22,8 +22,8 @@ import h11 -from ..base import Request, Response -from ..exceptions import ( +from .base import Request, Response +from .exceptions import ( ConnectTimeoutError, NewConnectionError, SubjectAltNameWarning, @@ -33,10 +33,10 @@ InvalidBodyError, ProtocolError, ) -from hip.packages import six -from ..util import ssl_ as ssl_util -from .._backends._common import LoopAbort -from .._backends._loader import load_backend, normalize_backend +from .packages import six +from .util import ssl_ as ssl_util +from ._backends._common import LoopAbort +from ._backends._loader import load_backend, normalize_backend try: import ssl diff --git a/src/hip/_async/connectionpool.py b/src/ahip/connectionpool.py similarity index 98% rename from src/hip/_async/connectionpool.py rename to src/ahip/connectionpool.py index c6c50568..a1da0844 100644 --- a/src/hip/_async/connectionpool.py +++ b/src/ahip/connectionpool.py @@ -10,8 +10,8 @@ import h11 -from ..base import Request, DEFAULT_PORTS -from ..exceptions import ( +from .base import Request, DEFAULT_PORTS +from .exceptions import ( ClosedPoolError, ProtocolError, EmptyPoolError, @@ -24,32 +24,32 @@ InsecureRequestWarning, NewConnectionError, ) -from hip.packages.ssl_match_hostname import CertificateError -from hip.packages import six -from hip.packages.six.moves import queue +from .packages.ssl_match_hostname import CertificateError +from .packages import six +from .packages.six.moves import queue from .request import RequestMethods from .response import HTTPResponse from .connection import HTTP1Connection -from ..util.connection import is_connection_dropped -from ..util.request import set_file_position -from ..util.retry import Retry -from ..util.ssl_ import ( +from .util.connection import is_connection_dropped +from .util.request import set_file_position +from .util.retry import Retry +from .util.ssl_ import ( create_ssl_context, merge_context_settings, resolve_ssl_version, resolve_cert_reqs, BaseSSLError, ) -from ..util.timeout import Timeout -from ..util.url import ( +from .util.timeout import Timeout +from .util.url import ( get_host, parse_url, Url, _normalize_host as normalize_host, _encode_target, ) -from ..util.queue import LifoQueue +from .util.queue import LifoQueue try: import ssl @@ -59,7 +59,7 @@ xrange = six.moves.xrange -log = logging.getLogger(__name__) +log = logging.getLogger("hip.connectionpool") _Default = object() diff --git a/src/hip/_backends/__init__.py b/src/ahip/contrib/__init__.py similarity index 100% rename from src/hip/_backends/__init__.py rename to src/ahip/contrib/__init__.py diff --git a/src/hip/contrib/__init__.py b/src/ahip/contrib/_securetransport/__init__.py similarity index 100% rename from src/hip/contrib/__init__.py rename to src/ahip/contrib/_securetransport/__init__.py diff --git a/src/hip/contrib/_securetransport/bindings.py b/src/ahip/contrib/_securetransport/bindings.py similarity index 100% rename from src/hip/contrib/_securetransport/bindings.py rename to src/ahip/contrib/_securetransport/bindings.py diff --git a/src/hip/contrib/_securetransport/low_level.py b/src/ahip/contrib/_securetransport/low_level.py similarity index 100% rename from src/hip/contrib/_securetransport/low_level.py rename to src/ahip/contrib/_securetransport/low_level.py diff --git a/src/hip/contrib/securetransport.py b/src/ahip/contrib/securetransport.py similarity index 99% rename from src/hip/contrib/securetransport.py rename to src/ahip/contrib/securetransport.py index e8f732e2..665a9475 100644 --- a/src/hip/contrib/securetransport.py +++ b/src/ahip/contrib/securetransport.py @@ -19,7 +19,7 @@ To use this module, simply import and inject it:: - import hp.contrib.securetransport + import hip.contrib.securetransport hip.contrib.securetransport.inject_into_hip() Happy TLSing! diff --git a/src/hip/contrib/socks.py b/src/ahip/contrib/socks.py similarity index 99% rename from src/hip/contrib/socks.py rename to src/ahip/contrib/socks.py index ec279e6c..7f0a0c2a 100644 --- a/src/hip/contrib/socks.py +++ b/src/ahip/contrib/socks.py @@ -54,7 +54,7 @@ from socket import error as SocketError, timeout as SocketTimeout -from .._sync.connection import HTTP1Connection +from ..connection import HTTP1Connection from ..connectionpool import HTTPConnectionPool, HTTPSConnectionPool from ..exceptions import ConnectTimeoutError, NewConnectionError from ..poolmanager import PoolManager diff --git a/src/hip/exceptions.py b/src/ahip/exceptions.py similarity index 100% rename from src/hip/exceptions.py rename to src/ahip/exceptions.py diff --git a/src/hip/fields.py b/src/ahip/fields.py similarity index 100% rename from src/hip/fields.py rename to src/ahip/fields.py diff --git a/src/hip/filepost.py b/src/ahip/filepost.py similarity index 100% rename from src/hip/filepost.py rename to src/ahip/filepost.py diff --git a/src/hip/packages/__init__.py b/src/ahip/packages/__init__.py similarity index 100% rename from src/hip/packages/__init__.py rename to src/ahip/packages/__init__.py diff --git a/src/hip/packages/six.py b/src/ahip/packages/six.py similarity index 100% rename from src/hip/packages/six.py rename to src/ahip/packages/six.py diff --git a/src/hip/packages/ssl_match_hostname/__init__.py b/src/ahip/packages/ssl_match_hostname/__init__.py similarity index 100% rename from src/hip/packages/ssl_match_hostname/__init__.py rename to src/ahip/packages/ssl_match_hostname/__init__.py diff --git a/src/hip/packages/ssl_match_hostname/_implementation.py b/src/ahip/packages/ssl_match_hostname/_implementation.py similarity index 100% rename from src/hip/packages/ssl_match_hostname/_implementation.py rename to src/ahip/packages/ssl_match_hostname/_implementation.py diff --git a/src/hip/_async/poolmanager.py b/src/ahip/poolmanager.py similarity index 97% rename from src/hip/_async/poolmanager.py rename to src/ahip/poolmanager.py index 5a63ccf5..609248bf 100644 --- a/src/hip/_async/poolmanager.py +++ b/src/ahip/poolmanager.py @@ -3,22 +3,22 @@ import functools import logging -from .._collections import RecentlyUsedContainer -from ..base import DEFAULT_PORTS +from ._collections import RecentlyUsedContainer +from .base import DEFAULT_PORTS from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool -from ..exceptions import LocationValueError, MaxRetryError, ProxySchemeUnknown -from ..packages import six -from ..packages.six.moves.urllib.parse import urljoin +from .exceptions import LocationValueError, MaxRetryError, ProxySchemeUnknown +from .packages import six +from .packages.six.moves.urllib.parse import urljoin from .request import RequestMethods -from ..util.url import parse_url -from ..util.request import set_file_position -from ..util.retry import Retry +from .util.url import parse_url +from .util.request import set_file_position +from .util.retry import Retry __all__ = ["PoolManager", "ProxyManager", "proxy_from_url"] -log = logging.getLogger(__name__) +log = logging.getLogger("hip.poolmanager") SSL_KEYWORDS = ( "key_file", diff --git a/src/hip/_async/request.py b/src/ahip/request.py similarity index 97% rename from src/hip/_async/request.py rename to src/ahip/request.py index 2d4939d0..a43803f5 100644 --- a/src/hip/_async/request.py +++ b/src/ahip/request.py @@ -1,8 +1,8 @@ from __future__ import absolute_import -from ..filepost import encode_multipart_formdata -from ..packages import six -from ..packages.six.moves.urllib.parse import urlencode +from .filepost import encode_multipart_formdata +from .packages import six +from .packages.six.moves.urllib.parse import urlencode __all__ = ["RequestMethods"] diff --git a/src/hip/_async/response.py b/src/ahip/response.py similarity index 98% rename from src/hip/_async/response.py rename to src/ahip/response.py index 3836e9bf..a87de44e 100644 --- a/src/hip/_async/response.py +++ b/src/ahip/response.py @@ -13,12 +13,12 @@ import h11 -from .._collections import HTTPHeaderDict -from ..exceptions import ProtocolError, DecodeError, ReadTimeoutError -from hip.packages.six import string_types as basestring -from ..util.ssl_ import BaseSSLError +from ._collections import HTTPHeaderDict +from .exceptions import ProtocolError, DecodeError, ReadTimeoutError +from .packages.six import string_types as basestring +from .util.ssl_ import BaseSSLError -log = logging.getLogger(__name__) +log = logging.getLogger("hip.response") class DeflateDecoder(object): diff --git a/src/hip/util/__init__.py b/src/ahip/util/__init__.py similarity index 100% rename from src/hip/util/__init__.py rename to src/ahip/util/__init__.py diff --git a/src/hip/util/connection.py b/src/ahip/util/connection.py similarity index 100% rename from src/hip/util/connection.py rename to src/ahip/util/connection.py diff --git a/src/hip/util/queue.py b/src/ahip/util/queue.py similarity index 100% rename from src/hip/util/queue.py rename to src/ahip/util/queue.py diff --git a/src/hip/util/request.py b/src/ahip/util/request.py similarity index 100% rename from src/hip/util/request.py rename to src/ahip/util/request.py diff --git a/src/hip/util/retry.py b/src/ahip/util/retry.py similarity index 99% rename from src/hip/util/retry.py rename to src/ahip/util/retry.py index b9683c8e..2924d22b 100644 --- a/src/hip/util/retry.py +++ b/src/ahip/util/retry.py @@ -17,7 +17,7 @@ from ..packages import six -log = logging.getLogger(__name__) +log = logging.getLogger("hip.util.retry") # Data structure for representing the metadata of requests that result in a retry. diff --git a/src/hip/util/ssl_.py b/src/ahip/util/ssl_.py similarity index 99% rename from src/hip/util/ssl_.py rename to src/ahip/util/ssl_.py index 82fefbb0..9c56e836 100644 --- a/src/hip/util/ssl_.py +++ b/src/ahip/util/ssl_.py @@ -26,7 +26,7 @@ HASHFUNC_MAP = {32: md5, 40: sha1, 64: sha256} -log = logging.getLogger(__name__) +log = logging.getLogger("hip.util.ssl_") def _const_compare_digest_backport(a, b): diff --git a/src/hip/util/timeout.py b/src/ahip/util/timeout.py similarity index 100% rename from src/hip/util/timeout.py rename to src/ahip/util/timeout.py diff --git a/src/hip/util/url.py b/src/ahip/util/url.py similarity index 100% rename from src/hip/util/url.py rename to src/ahip/util/url.py diff --git a/src/hip/util/wait.py b/src/ahip/util/wait.py similarity index 100% rename from src/hip/util/wait.py rename to src/ahip/util/wait.py diff --git a/src/hip/connectionpool.py b/src/hip/connectionpool.py deleted file mode 100644 index 270ddea0..00000000 --- a/src/hip/connectionpool.py +++ /dev/null @@ -1,13 +0,0 @@ -from ._sync.connectionpool import ( - ConnectionPool, - HTTPConnectionPool, - HTTPSConnectionPool, - connection_from_url, -) - -__all__ = [ - "ConnectionPool", - "HTTPConnectionPool", - "HTTPSConnectionPool", - "connection_from_url", -] diff --git a/src/hip/contrib/_securetransport/__init__.py b/src/hip/contrib/_securetransport/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/hip/poolmanager.py b/src/hip/poolmanager.py deleted file mode 100644 index 192dfafa..00000000 --- a/src/hip/poolmanager.py +++ /dev/null @@ -1,3 +0,0 @@ -from ._sync.poolmanager import PoolManager, ProxyManager, proxy_from_url - -__all__ = ["PoolManager", "ProxyManager", "proxy_from_url"] diff --git a/src/hip/request.py b/src/hip/request.py deleted file mode 100644 index 1ecad747..00000000 --- a/src/hip/request.py +++ /dev/null @@ -1,3 +0,0 @@ -from ._sync.request import RequestMethods - -__all__ = ["RequestMethods"] diff --git a/src/hip/response.py b/src/hip/response.py deleted file mode 100644 index 0bcddbd3..00000000 --- a/src/hip/response.py +++ /dev/null @@ -1,3 +0,0 @@ -from ._sync.response import DeflateDecoder, GzipDecoder, HTTPResponse, brotli - -__all__ = ["DeflateDecoder", "GzipDecoder", "HTTPResponse", "brotli"] diff --git a/test/test_connection.py b/test/test_connection.py index 8eb2bc29..cda5ab50 100644 --- a/test/test_connection.py +++ b/test/test_connection.py @@ -5,7 +5,7 @@ import pytest from hip.base import Request -from hip._sync.connection import _request_bytes_iterable, RECENT_DATE +from hip.connection import _request_bytes_iterable, RECENT_DATE from hip.util.ssl_ import CertificateError, match_hostname diff --git a/test/test_connectionpool.py b/test/test_connectionpool.py index 3d92c8fd..1be9e8c1 100644 --- a/test/test_connectionpool.py +++ b/test/test_connectionpool.py @@ -9,7 +9,7 @@ HTTPConnectionPool, HTTPSConnectionPool, ) -from hip._sync.connection import HTTP1Connection +from hip.connection import HTTP1Connection from hip.response import HTTPResponse from hip.util.timeout import Timeout from hip.packages.six.moves.queue import Empty diff --git a/test/test_poolmanager.py b/test/test_poolmanager.py index d819c455..626c2da4 100644 --- a/test/test_poolmanager.py +++ b/test/test_poolmanager.py @@ -3,7 +3,7 @@ import pytest from hip.poolmanager import PoolManager -from hip._sync.poolmanager import key_fn_by_scheme, PoolKey +from hip.poolmanager import key_fn_by_scheme, PoolKey from hip import connection_from_url from hip.exceptions import ClosedPoolError, LocationValueError from hip.util import retry, timeout, ssl_ diff --git a/test/test_sync_connection.py b/test/test_sync_connection.py index e9235ef7..aac300c9 100644 --- a/test/test_sync_connection.py +++ b/test/test_sync_connection.py @@ -16,7 +16,7 @@ from hip.base import Request from hip._backends.sync_backend import SyncSocket -from hip._sync.connection import HTTP1Connection +from hip.connection import HTTP1Connection # Objects and globals for handling scenarios. diff --git a/test/test_util.py b/test/test_util.py index ed8cdfe2..3c7e0700 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -552,7 +552,7 @@ def test_split_first(self, input, expected): def test_add_stderr_logger(self): handler = add_stderr_logger(level=logging.INFO) # Don't actually print debug - logger = logging.getLogger("hip") + logger = logging.getLogger("ahip") assert handler in logger.handlers logger.debug("Testing add_stderr_logger") diff --git a/test/with_dummyserver/async/test_poolmanager.py b/test/with_dummyserver/async/test_poolmanager.py index bf3987e5..af06e5d2 100644 --- a/test/with_dummyserver/async/test_poolmanager.py +++ b/test/with_dummyserver/async/test_poolmanager.py @@ -1,4 +1,4 @@ -from hip import AsyncPoolManager +from ahip import PoolManager from test.with_dummyserver import conftest @@ -7,7 +7,7 @@ class TestPoolManager: @conftest.test_all_backends async def test_redirect(self, http_server, backend, anyio_backend): base_url = "http://{}:{}".format(http_server.host, http_server.port) - with AsyncPoolManager(backend=backend) as http: + with PoolManager(backend=backend) as http: r = await http.request( "GET", "%s/redirect" % base_url, diff --git a/test/with_dummyserver/test_https.py b/test/with_dummyserver/test_https.py index c2cbc23e..9c0325a8 100644 --- a/test/with_dummyserver/test_https.py +++ b/test/with_dummyserver/test_https.py @@ -43,7 +43,7 @@ LONG_TIMEOUT, ) from hip import HTTPSConnectionPool -from hip._sync.connection import RECENT_DATE +from hip.connection import RECENT_DATE from hip.exceptions import ( SSLError, ConnectTimeoutError, @@ -580,7 +580,7 @@ def test_ssl_correct_system_time(self): @onlyPy279OrNewer def test_ssl_wrong_system_time(self): - with mock.patch("hip._sync.connection.datetime") as mock_date: + with mock.patch("hip.connection.datetime") as mock_date: mock_date.date.today.return_value = datetime.date(1970, 1, 1) w = self._request_without_resource_warnings("GET", "/")