Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
Split top-level package namespaces into 'hip' and 'ahip'
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed May 8, 2020
1 parent 0706f48 commit ae4f68c
Show file tree
Hide file tree
Showing 55 changed files with 65 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Project-specific generated files
docs/build/
src/hip/_sync/
src/hip/
test/with_dummyserver/sync/

bench/results/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions demo/async-demo.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")])
},
)
32 changes: 4 additions & 28 deletions src/hip/__init__.py → src/ahip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/hip/_async/connection.py → src/ahip/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
26 changes: 13 additions & 13 deletions src/hip/_async/connectionpool.py → src/ahip/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -59,7 +59,7 @@

xrange = six.moves.xrange

log = logging.getLogger(__name__)
log = logging.getLogger("hip.connectionpool")

_Default = object()

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion src/hip/contrib/socks.py → src/ahip/contrib/socks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions src/hip/_async/poolmanager.py → src/ahip/poolmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/hip/_async/request.py → src/ahip/request.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
10 changes: 5 additions & 5 deletions src/hip/_async/response.py → src/ahip/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/hip/util/retry.py → src/ahip/util/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/hip/util/ssl_.py → src/ahip/util/ssl_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions src/hip/connectionpool.py

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions src/hip/poolmanager.py

This file was deleted.

3 changes: 0 additions & 3 deletions src/hip/request.py

This file was deleted.

3 changes: 0 additions & 3 deletions src/hip/response.py

This file was deleted.

2 changes: 1 addition & 1 deletion test/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion test/test_connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_poolmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
2 changes: 1 addition & 1 deletion test/test_sync_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions test/with_dummyserver/async/test_poolmanager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hip import AsyncPoolManager
from ahip import PoolManager

from test.with_dummyserver import conftest

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/with_dummyserver/test_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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", "/")
Expand Down

0 comments on commit ae4f68c

Please sign in to comment.