Skip to content

Commit

Permalink
Create and use core_socks package
Browse files Browse the repository at this point in the history
  • Loading branch information
romis2012 committed Jul 12, 2020
1 parent c5cfa1e commit e85ce13
Show file tree
Hide file tree
Showing 57 changed files with 1,202 additions and 1,315 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[run]
omit =
*/chain_proxy.py
httpx_socks/_proxy/basic_auth.py
httpx_socks/core_socks/_basic_auth.py
4 changes: 2 additions & 2 deletions httpx_socks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = 'httpx-socks'
__version__ = '0.2.1'
__version__ = '0.2.2'

from ._proxy import (
from .core_socks import (
ProxyError,
ProxyTimeoutError,
ProxyConnectionError,
Expand Down
36 changes: 20 additions & 16 deletions httpx_socks/_async_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from httpcore._utils import url_to_origin # noqa
from httpx._config import SSLConfig # noqa

from ._proxy import ProxyType, parse_proxy_url
from .core_socks import ProxyType, parse_proxy_url


class AsyncProxyTransport(AsyncConnectionPool):
Expand All @@ -22,9 +22,6 @@ def __init__(self, *, proxy_type: ProxyType,
trust_env=True,
loop=None):

if loop is None:
loop = asyncio.get_event_loop()

self._loop = loop
self._proxy_type = proxy_type
self._proxy_host = proxy_host
Expand Down Expand Up @@ -85,23 +82,28 @@ async def _open_stream(self, host, port, connect_timeout, ssl_context):
backend = sniffio.current_async_library()

if backend == 'asyncio':
from ._proxy._asyncio import create_proxy
if self._loop is None:
self._loop = asyncio.get_event_loop()

from .core_socks.asyn.asyncio import Proxy

proxy = create_proxy(
proxy = Proxy.create(
loop=self._loop,
proxy_type=self._proxy_type,
host=self._proxy_host, port=self._proxy_port,
username=self._username, password=self._password,
host=self._proxy_host,
port=self._proxy_port,
username=self._username,
password=self._password,
rdns=self._rdns
)

await proxy.connect(host, port, timeout=connect_timeout)
sock = await proxy.connect(host, port, timeout=connect_timeout)
# noinspection PyTypeChecker
stream_reader, stream_writer = await asyncio.open_connection(
loop=self._loop,
host=None,
port=None,
sock=proxy.socket,
sock=sock,
ssl=ssl_context,
server_hostname=host if ssl_context else None,
)
Expand All @@ -110,18 +112,20 @@ async def _open_stream(self, host, port, connect_timeout, ssl_context):
)

elif backend == 'trio':
from ._proxy._trio import create_proxy # noqa
from .core_socks.asyn.trio import Proxy

proxy = create_proxy(
proxy = Proxy.create(
proxy_type=self._proxy_type,
host=self._proxy_host, port=self._proxy_port,
username=self._username, password=self._password,
host=self._proxy_host,
port=self._proxy_port,
username=self._username,
password=self._password,
rdns=self._rdns
)

await proxy.connect(host, port, timeout=connect_timeout)
sock = await proxy.connect(host, port, timeout=connect_timeout)

stream = trio.SocketStream(proxy.socket)
stream = trio.SocketStream(sock)

if ssl_context is not None:
stream = trio.SSLStream(
Expand Down
11 changes: 0 additions & 11 deletions httpx_socks/_proxy/__init__.py

This file was deleted.

15 changes: 0 additions & 15 deletions httpx_socks/_proxy/_asyncio/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions httpx_socks/_proxy/_asyncio/abc.py

This file was deleted.

119 changes: 0 additions & 119 deletions httpx_socks/_proxy/_asyncio/base_proxy.py

This file was deleted.

35 changes: 0 additions & 35 deletions httpx_socks/_proxy/_asyncio/chain_proxy.py

This file was deleted.

31 changes: 0 additions & 31 deletions httpx_socks/_proxy/_asyncio/factory.py

This file was deleted.

Loading

0 comments on commit e85ce13

Please sign in to comment.