File tree Expand file tree Collapse file tree 9 files changed +44
-5
lines changed Expand file tree Collapse file tree 9 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ async def connect(
60
60
stacklevel = 2 ,
61
61
)
62
62
63
+ local_host = kwargs .get ('local_host' )
63
64
try :
64
65
with anyio .fail_after (timeout ):
65
66
if _stream is None :
@@ -68,6 +69,7 @@ async def connect(
68
69
await connect_tcp (
69
70
host = self ._proxy_host ,
70
71
port = self ._proxy_port ,
72
+ local_host = local_host ,
71
73
)
72
74
)
73
75
except OSError as e :
Original file line number Diff line number Diff line change 1
1
import ssl
2
- from typing import Optional
2
+ from typing import Any , Optional
3
3
4
4
import anyio
5
5
@@ -47,16 +47,19 @@ async def connect(
47
47
dest_port : int ,
48
48
dest_ssl : Optional [ssl .SSLContext ] = None ,
49
49
timeout : Optional [float ] = None ,
50
+ ** kwargs : Any ,
50
51
) -> AnyioSocketStream :
51
52
if timeout is None :
52
53
timeout = DEFAULT_TIMEOUT
53
54
55
+ local_host = kwargs .get ('local_host' )
54
56
try :
55
57
with anyio .fail_after (timeout ):
56
58
return await self ._connect (
57
59
dest_host = dest_host ,
58
60
dest_port = dest_port ,
59
61
dest_ssl = dest_ssl ,
62
+ local_host = local_host ,
60
63
)
61
64
except TimeoutError as e :
62
65
raise ProxyTimeoutError ('Proxy connection timed out: {}' .format (timeout )) from e
@@ -66,12 +69,14 @@ async def _connect(
66
69
dest_host : str ,
67
70
dest_port : int ,
68
71
dest_ssl : Optional [ssl .SSLContext ] = None ,
72
+ local_host : Optional [str ] = None ,
69
73
) -> AnyioSocketStream :
70
74
if self ._forward is None :
71
75
try :
72
76
stream = await connect_tcp (
73
77
host = self ._proxy_host ,
74
78
port = self ._proxy_port ,
79
+ local_host = local_host ,
75
80
)
76
81
except OSError as e :
77
82
raise ProxyConnectionError (
Original file line number Diff line number Diff line change @@ -66,23 +66,32 @@ async def connect(
66
66
stacklevel = 2 ,
67
67
)
68
68
69
+ local_addr = kwargs .get ('local_addr' )
69
70
try :
70
71
async with async_timeout .timeout (timeout ):
71
72
return await self ._connect (
72
73
dest_host = dest_host ,
73
74
dest_port = dest_port ,
74
75
_socket = _socket ,
76
+ local_addr = local_addr ,
75
77
)
76
78
except asyncio .TimeoutError as e :
77
79
raise ProxyTimeoutError (f'Proxy connection timed out: { timeout } ' ) from e
78
80
79
- async def _connect (self , dest_host , dest_port , _socket = None ) -> socket .socket :
81
+ async def _connect (
82
+ self ,
83
+ dest_host ,
84
+ dest_port ,
85
+ _socket = None ,
86
+ local_addr = None ,
87
+ ) -> socket .socket :
80
88
if _socket is None :
81
89
try :
82
90
_socket = await connect_tcp (
83
91
host = self ._proxy_host ,
84
92
port = self ._proxy_port ,
85
93
loop = self ._loop ,
94
+ local_addr = local_addr ,
86
95
)
87
96
except OSError as e :
88
97
msg = 'Could not connect to proxy {}:{} [{}]' .format (
Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import ssl
3
- from typing import Optional
3
+ from typing import Any , Optional , Tuple
4
4
import warnings
5
5
import sys
6
6
@@ -68,16 +68,19 @@ async def connect(
68
68
dest_port : int ,
69
69
dest_ssl : Optional [ssl .SSLContext ] = None ,
70
70
timeout : Optional [float ] = None ,
71
+ ** kwargs : Any ,
71
72
) -> AsyncioSocketStream :
72
73
if timeout is None :
73
74
timeout = DEFAULT_TIMEOUT
74
75
76
+ local_addr = kwargs .get ('local_addr' )
75
77
try :
76
78
async with async_timeout .timeout (timeout ):
77
79
return await self ._connect (
78
80
dest_host = dest_host ,
79
81
dest_port = dest_port ,
80
82
dest_ssl = dest_ssl ,
83
+ local_addr = local_addr ,
81
84
)
82
85
except asyncio .TimeoutError as e :
83
86
raise ProxyTimeoutError ('Proxy connection timed out: {}' .format (timeout )) from e
@@ -87,13 +90,15 @@ async def _connect(
87
90
dest_host : str ,
88
91
dest_port : int ,
89
92
dest_ssl : Optional [ssl .SSLContext ] = None ,
93
+ local_addr : Optional [Tuple [str , int ]] = None ,
90
94
) -> AsyncioSocketStream :
91
95
if self ._forward is None :
92
96
try :
93
97
stream = await connect_tcp (
94
98
host = self ._proxy_host ,
95
99
port = self ._proxy_port ,
96
100
loop = self ._loop ,
101
+ local_addr = local_addr ,
97
102
)
98
103
except OSError as e :
99
104
raise ProxyConnectionError (
Original file line number Diff line number Diff line change @@ -55,13 +55,15 @@ async def connect(
55
55
stacklevel = 2 ,
56
56
)
57
57
58
+ local_addr = kwargs .get ('local_addr' )
58
59
try :
59
60
return await curio .timeout_after (
60
61
timeout ,
61
62
self ._connect ,
62
63
dest_host ,
63
64
dest_port ,
64
65
_socket ,
66
+ local_addr ,
65
67
)
66
68
except curio .TaskTimeout as e :
67
69
raise ProxyTimeoutError (f'Proxy connection timed out: { timeout } ' ) from e
@@ -71,12 +73,14 @@ async def _connect(
71
73
dest_host : str ,
72
74
dest_port : int ,
73
75
_socket = None ,
76
+ local_addr = None ,
74
77
):
75
78
if _socket is None :
76
79
try :
77
80
_socket = await connect_tcp (
78
81
host = self ._proxy_host ,
79
82
port = self ._proxy_port ,
83
+ local_addr = local_addr ,
80
84
)
81
85
except OSError as e :
82
86
msg = 'Could not connect to proxy {}:{} [{}]' .format (
Original file line number Diff line number Diff line change @@ -54,12 +54,14 @@ async def connect(
54
54
stacklevel = 2 ,
55
55
)
56
56
57
+ local_addr = kwargs .get ('local_addr' )
57
58
try :
58
59
with trio .fail_after (timeout ):
59
60
return await self ._connect (
60
61
dest_host = dest_host ,
61
62
dest_port = dest_port ,
62
63
_socket = _socket ,
64
+ local_addr = local_addr ,
63
65
)
64
66
except trio .TooSlowError as e :
65
67
raise ProxyTimeoutError ('Proxy connection timed out: {}' .format (timeout )) from e
@@ -69,12 +71,14 @@ async def _connect(
69
71
dest_host : str ,
70
72
dest_port : int ,
71
73
_socket = None ,
74
+ local_addr = None ,
72
75
) -> trio .socket .SocketType :
73
76
if _socket is None :
74
77
try :
75
78
_socket = await connect_tcp (
76
79
host = self ._proxy_host ,
77
80
port = self ._proxy_port ,
81
+ local_addr = local_addr ,
78
82
)
79
83
except OSError as e :
80
84
msg = 'Could not connect to proxy {}:{} [{}]' .format (
Original file line number Diff line number Diff line change 1
1
import ssl
2
- from typing import Optional
2
+ from typing import Any , Optional
3
3
4
4
import trio
5
5
@@ -47,16 +47,19 @@ async def connect(
47
47
dest_port : int ,
48
48
dest_ssl : Optional [ssl .SSLContext ] = None ,
49
49
timeout : Optional [float ] = None ,
50
+ ** kwargs : Any ,
50
51
) -> TrioSocketStream :
51
52
if timeout is None :
52
53
timeout = DEFAULT_TIMEOUT
53
54
55
+ local_addr = kwargs .get ('local_addr' )
54
56
try :
55
57
with trio .fail_after (timeout ):
56
58
return await self ._connect (
57
59
dest_host = dest_host ,
58
60
dest_port = dest_port ,
59
61
dest_ssl = dest_ssl ,
62
+ local_addr = local_addr ,
60
63
)
61
64
except trio .TooSlowError as e :
62
65
raise ProxyTimeoutError (f'Proxy connection timed out: { timeout } ' ) from e
@@ -66,12 +69,14 @@ async def _connect(
66
69
dest_host : str ,
67
70
dest_port : int ,
68
71
dest_ssl : Optional [ssl .SSLContext ] = None ,
72
+ local_addr : Optional [str ] = None ,
69
73
) -> TrioSocketStream :
70
74
if self ._forward is None :
71
75
try :
72
76
stream = await connect_tcp (
73
77
host = self ._proxy_host ,
74
78
port = self ._proxy_port ,
79
+ local_addr = local_addr ,
75
80
)
76
81
except OSError as e :
77
82
raise ProxyConnectionError (
Original file line number Diff line number Diff line change @@ -55,11 +55,13 @@ def connect(
55
55
)
56
56
57
57
if _socket is None :
58
+ local_addr = kwargs .get ('local_addr' )
58
59
try :
59
60
_socket = connect_tcp (
60
61
host = self ._proxy_host ,
61
62
port = self ._proxy_port ,
62
63
timeout = timeout ,
64
+ local_addr = local_addr ,
63
65
)
64
66
except OSError as e :
65
67
msg = 'Could not connect to proxy {}:{} [{}]' .format (
Original file line number Diff line number Diff line change 1
1
import socket
2
2
import ssl
3
- from typing import Optional
3
+ from typing import Any , Optional
4
4
5
5
from ._connect import connect_tcp
6
6
from ._stream import SyncSocketStream
@@ -45,16 +45,19 @@ def connect(
45
45
dest_port : int ,
46
46
dest_ssl : Optional [ssl .SSLContext ] = None ,
47
47
timeout : Optional [float ] = None ,
48
+ ** kwargs : Any ,
48
49
) -> SyncSocketStream :
49
50
if timeout is None :
50
51
timeout = DEFAULT_TIMEOUT
51
52
52
53
if self ._forward is None :
54
+ local_addr = kwargs .get ('local_addr' )
53
55
try :
54
56
stream = connect_tcp (
55
57
host = self ._proxy_host ,
56
58
port = self ._proxy_port ,
57
59
timeout = timeout ,
60
+ local_addr = local_addr ,
58
61
)
59
62
except OSError as e :
60
63
msg = 'Could not connect to proxy {}:{} [{}]' .format (
You can’t perform that action at this time.
0 commit comments