python-socks 2.1.1__py3-none-any.whl → 2.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,8 @@
1
1
  import socket
2
2
  import ssl
3
- from typing import Optional
4
3
 
4
+ from ._connect import connect_tcp
5
5
  from ._stream import SyncSocketStream
6
- from .._connect import connect_tcp
7
6
  from .._resolver import SyncResolver
8
7
  from ... import _abc as abc
9
8
  from ..._errors import ProxyConnectionError, ProxyTimeoutError
@@ -15,24 +14,18 @@ DEFAULT_TIMEOUT = 60
15
14
 
16
15
 
17
16
  class SyncProxy(abc.SyncProxy):
18
- _stream: Optional[SyncSocketStream]
19
-
20
17
  def __init__(
21
18
  self,
22
19
  proxy_host: str,
23
20
  proxy_port: int,
24
21
  proxy_ssl: ssl.SSLContext = None,
22
+ forward: 'SyncProxy' = None,
25
23
  ):
26
24
  self._proxy_host = proxy_host
27
25
  self._proxy_port = proxy_port
28
26
  self._proxy_ssl = proxy_ssl
27
+ self._forward = forward
29
28
 
30
- self._dest_host = None
31
- self._dest_port = None
32
- self._dest_ssl = None
33
- self._timeout = None
34
-
35
- self._stream = None
36
29
  self._resolver = SyncResolver()
37
30
 
38
31
  def connect(
@@ -41,74 +34,67 @@ class SyncProxy(abc.SyncProxy):
41
34
  dest_port: int,
42
35
  dest_ssl: ssl.SSLContext = None,
43
36
  timeout: float = None,
44
- _stream: SyncSocketStream = None,
45
37
  ) -> SyncSocketStream:
46
-
47
38
  if timeout is None:
48
39
  timeout = DEFAULT_TIMEOUT
49
40
 
50
- self._dest_host = dest_host
51
- self._dest_port = dest_port
52
- self._dest_ssl = dest_ssl
53
- self._timeout = timeout
54
-
55
41
  try:
56
- if _stream is None:
57
- sock = connect_tcp(
42
+ if self._forward is None:
43
+ stream = connect_tcp(
58
44
  host=self._proxy_host,
59
45
  port=self._proxy_port,
60
46
  timeout=timeout,
61
47
  )
62
- self._stream = SyncSocketStream(sock)
63
48
  else:
64
- self._stream = _stream
49
+ stream = self._forward.connect(
50
+ dest_host=self._proxy_host,
51
+ dest_port=self._proxy_port,
52
+ timeout=timeout,
53
+ )
54
+ except OSError as e:
55
+ msg = 'Could not connect to proxy {}:{} [{}]'.format(
56
+ self._proxy_host,
57
+ self._proxy_port,
58
+ e.strerror,
59
+ )
60
+ raise ProxyConnectionError(e.errno, msg) from e
65
61
 
62
+ try:
66
63
  if self._proxy_ssl is not None:
67
- self._stream = self._stream.start_tls(
64
+ stream = stream.start_tls(
68
65
  hostname=self._proxy_host,
69
66
  ssl_context=self._proxy_ssl,
70
67
  )
71
68
 
72
- self._negotiate()
69
+ self._negotiate(
70
+ stream=stream,
71
+ dest_host=dest_host,
72
+ dest_port=dest_port,
73
+ )
73
74
 
74
- if self._dest_ssl is not None:
75
- self._stream = self._stream.start_tls(
76
- hostname=self._dest_host,
77
- ssl_context=self._dest_ssl,
75
+ if dest_ssl is not None:
76
+ stream = stream.start_tls(
77
+ hostname=dest_host,
78
+ ssl_context=dest_ssl,
78
79
  )
79
80
 
80
- return self._stream
81
+ return stream
81
82
 
82
83
  except socket.timeout as e:
83
- self._close()
84
- raise ProxyTimeoutError('Proxy connection timed out: {}'.format(self._timeout)) from e
85
- except OSError as e:
86
- self._close()
87
- msg = 'Could not connect to proxy {}:{} [{}]'.format(
88
- self._proxy_host,
89
- self._proxy_port,
90
- e.strerror,
91
- )
92
- raise ProxyConnectionError(e.errno, msg) from e
84
+ stream.close()
85
+ raise ProxyTimeoutError('Proxy connection timed out: {}'.format(timeout)) from e
93
86
  except Exception:
94
- self._close()
87
+ stream.close()
95
88
  raise
96
89
 
97
- def _negotiate(self):
90
+ def _negotiate(
91
+ self,
92
+ stream: SyncSocketStream,
93
+ dest_host: str,
94
+ dest_port: int,
95
+ ):
98
96
  raise NotImplementedError
99
97
 
100
- def _close(self):
101
- if self._stream is not None:
102
- self._stream.close()
103
-
104
- @property
105
- def proxy_host(self):
106
- return self._proxy_host
107
-
108
- @property
109
- def proxy_port(self):
110
- return self._proxy_port
111
-
112
98
 
113
99
  class Socks5Proxy(SyncProxy):
114
100
  def __init__(
@@ -119,22 +105,29 @@ class Socks5Proxy(SyncProxy):
119
105
  password=None,
120
106
  rdns=None,
121
107
  proxy_ssl=None,
108
+ forward: 'SyncProxy' = None,
122
109
  ):
123
110
  super().__init__(
124
111
  proxy_host=proxy_host,
125
112
  proxy_port=proxy_port,
126
113
  proxy_ssl=proxy_ssl,
114
+ forward=forward,
127
115
  )
128
116
  self._username = username
129
117
  self._password = password
130
118
  self._rdns = rdns
131
119
 
132
- def _negotiate(self):
120
+ def _negotiate(
121
+ self,
122
+ stream: SyncSocketStream,
123
+ dest_host: str,
124
+ dest_port: int,
125
+ ):
133
126
  proto = Socks5Proto(
134
- stream=self._stream,
127
+ stream=stream,
135
128
  resolver=self._resolver,
136
- dest_host=self._dest_host,
137
- dest_port=self._dest_port,
129
+ dest_host=dest_host,
130
+ dest_port=dest_port,
138
131
  username=self._username,
139
132
  password=self._password,
140
133
  rdns=self._rdns,
@@ -150,21 +143,28 @@ class Socks4Proxy(SyncProxy):
150
143
  user_id=None,
151
144
  rdns=None,
152
145
  proxy_ssl=None,
146
+ forward: 'SyncProxy' = None,
153
147
  ):
154
148
  super().__init__(
155
149
  proxy_host=proxy_host,
156
150
  proxy_port=proxy_port,
157
151
  proxy_ssl=proxy_ssl,
152
+ forward=forward,
158
153
  )
159
154
  self._user_id = user_id
160
155
  self._rdns = rdns
161
156
 
162
- def _negotiate(self):
157
+ def _negotiate(
158
+ self,
159
+ stream: SyncSocketStream,
160
+ dest_host: str,
161
+ dest_port: int,
162
+ ):
163
163
  proto = Socks4Proto(
164
- stream=self._stream,
164
+ stream=stream,
165
165
  resolver=self._resolver,
166
- dest_host=self._dest_host,
167
- dest_port=self._dest_port,
166
+ dest_host=dest_host,
167
+ dest_port=dest_port,
168
168
  user_id=self._user_id,
169
169
  rdns=self._rdns,
170
170
  )
@@ -179,20 +179,27 @@ class HttpProxy(SyncProxy):
179
179
  username=None,
180
180
  password=None,
181
181
  proxy_ssl=None,
182
+ forward: 'SyncProxy' = None,
182
183
  ):
183
184
  super().__init__(
184
185
  proxy_host=proxy_host,
185
186
  proxy_port=proxy_port,
186
187
  proxy_ssl=proxy_ssl,
188
+ forward=forward,
187
189
  )
188
190
  self._username = username
189
191
  self._password = password
190
192
 
191
- def _negotiate(self):
193
+ def _negotiate(
194
+ self,
195
+ stream: SyncSocketStream,
196
+ dest_host: str,
197
+ dest_port: int,
198
+ ):
192
199
  proto = HttpProto(
193
- stream=self._stream,
194
- dest_host=self._dest_host,
195
- dest_port=self._dest_port,
200
+ stream=stream,
201
+ dest_host=dest_host,
202
+ dest_port=dest_port,
196
203
  username=self._username,
197
204
  password=self._password,
198
205
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-socks
3
- Version: 2.1.1
3
+ Version: 2.3.0
4
4
  Summary: Core proxy (SOCKS4, SOCKS5, HTTP tunneling) functionality for Python
5
5
  Home-page: https://github.com/romis2012/python-socks
6
6
  Author: Roman Snegirev
@@ -5,7 +5,7 @@ python_socks/_errors.py,sha256=l2j03Zna_EJhNqF3yApTYuQ147BcY0k74pkT4HAlRp4,245
5
5
  python_socks/_helpers.py,sha256=XSNUT2Sz5F_HBNzvm_jIBjPZp79UHE2kxlWiZygy19M,2544
6
6
  python_socks/_proxy_factory.py,sha256=eZSP-HouPc6UGn8yKdsZi5QYncO0yDUprVH74vEZWBA,1606
7
7
  python_socks/_types.py,sha256=dgQifNf2mIwdKoX7YmI91H_lUsW9-Y0ZkZGlIV6_NNw,90
8
- python_socks/_version.py,sha256=RCZ8Y99VqqRvBlZi6XEdvgbOaGiEZVWuIEjUtsLtZiI,49
8
+ python_socks/_version.py,sha256=-6Mu54sg3gKrvjVhv3muuxHpG7KJInp-P1g6CfAOxJE,49
9
9
  python_socks/_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  python_socks/_proto/http.py,sha256=Yj6-uivDfHF9ONZSZJazZCuYlYbQ2I_hyip-Uf1ACm4,1798
11
11
  python_socks/_proto/http_async.py,sha256=HdxhKQHubpzQZ3VgOQU5cYTckUuTBiC3eHEgAploFs8,790
@@ -25,17 +25,23 @@ python_socks/async_/anyio/_factory.py,sha256=lPpUqtXJlIHVYY_juDJse7Un1F0GKmGm-2C
25
25
  python_socks/async_/anyio/_proxy.py,sha256=nMOAo0wL549qbSaLSQn8qybTO4gBunZ9hMmxDDAIV74,5339
26
26
  python_socks/async_/anyio/_resolver.py,sha256=LPRLmEzgKPGCqAbEMmLSMVtFkNVKha_2u08MhrZZ-CY,590
27
27
  python_socks/async_/anyio/_stream.py,sha256=OcCl4YkccA0-5hZh90CP4YmsBDLPwHpS3B0wCLytnAY,1614
28
+ python_socks/async_/anyio/v2/__init__.py,sha256=3Bv4ukDEyxzxCX8JlgpTZR2Bbwq6Fu3csK0ZiX-XHXQ,106
29
+ python_socks/async_/anyio/v2/_chain.py,sha256=baTCXD68hceOMWYITrUUSKv-B745RT4TdpQPDkSz68Y,593
30
+ python_socks/async_/anyio/v2/_connect.py,sha256=wOOuUxURCjIWOH1pd8H6gr3XZ3VnvRtmsAh97M_ULEA,330
31
+ python_socks/async_/anyio/v2/_factory.py,sha256=Hh6a95m-qKkX25pO98ph_LpcfWgo2ljwVxj_kgqB2TE,319
32
+ python_socks/async_/anyio/v2/_proxy.py,sha256=GO38rPyghr9d21HDQV5yOzlpoDA7SfVutysVHePb00M,5584
33
+ python_socks/async_/anyio/v2/_stream.py,sha256=40D3Pmb0rryk9gaQlmjpAMdiJi5H5O0xbBseblGG1FY,1616
28
34
  python_socks/async_/asyncio/__init__.py,sha256=v2rBc4jol3U7KH1AJmw179-GYqiibCTvRRsAzbfNbYg,364
29
35
  python_socks/async_/asyncio/_connect.py,sha256=niNKiz2o1kfeIPVR3kXW7YHZ2sTK_Uehgq9tmFwbp7w,1014
30
36
  python_socks/async_/asyncio/_proxy.py,sha256=UwzK54GCxqBCcMXmcRWhhwrJ35Pgs5jvujxzD-bL3AY,5814
31
37
  python_socks/async_/asyncio/_resolver.py,sha256=ROqOncuIub87J9_nMdvRTG_5zYOh8uafk265z0s2ORQ,681
32
38
  python_socks/async_/asyncio/_stream.py,sha256=RP7BIP9iFFy5nLRf9kHH7s1h_zPfo0yoEVKNpExqFcI,1021
33
39
  python_socks/async_/asyncio/v2/__init__.py,sha256=QpHsh2j7HntoF0eqA3c_LxL8V_V3lzVSKx9mQvSx0rE,94
34
- python_socks/async_/asyncio/v2/_chain.py,sha256=d5ahSRH44hHBb4SVwFiJJp9dZa0PmmRPk3DTxdC3rM0,873
35
- python_socks/async_/asyncio/v2/_connect.py,sha256=CeS6kqrIWN-xB4aUapjvu-AfbRbbbulvXJA7tdwU6gM,464
40
+ python_socks/async_/asyncio/v2/_chain.py,sha256=Yle3F3TKEpCo9Snd-T5hRnmfn9iWj2VNLb3UHz6yNiU,607
41
+ python_socks/async_/asyncio/v2/_connect.py,sha256=b3kQBR7L6wp-yvWVwtcdb4JUdQV04JW-DXF1g1P3gxI,587
36
42
  python_socks/async_/asyncio/v2/_factory.py,sha256=ZZfOOLRav1HNwuHXcjt9rVbkq0O34tCiUVR4rKK6JOU,323
37
- python_socks/async_/asyncio/v2/_proxy.py,sha256=zVIxbWwtymZ445TekYNBswOEBZ5is-MO9HQDyK4hoPs,6106
38
- python_socks/async_/asyncio/v2/_stream.py,sha256=lr9wO-f0-k6lO4B_UQKkaa6ErdHNyThuMX2hj3d2RrU,3464
43
+ python_socks/async_/asyncio/v2/_proxy.py,sha256=T8INqHi4dimnWt1zANyhbg6T7R7vhXz4aX2c5kFa9eI,6385
44
+ python_socks/async_/asyncio/v2/_stream.py,sha256=hBGM1q2kW1jdOmpSyq2hpsarmHeeoLllJfPunFHaCBM,3465
39
45
  python_socks/async_/curio/__init__.py,sha256=BJf4m4tC78V4BjJbvnm2-JdHT9XLbt14lT_rk2IOlgc,360
40
46
  python_socks/async_/curio/_connect.py,sha256=u1HRJ8n3OZbux-wETO9HuqZv9By2LGhhSsM78gnxr_0,328
41
47
  python_socks/async_/curio/_proxy.py,sha256=Y6FU0mitVTBFuTiEHoTEymM09ZnbZX2gr-ixsYAKWKE,4074
@@ -47,10 +53,10 @@ python_socks/async_/trio/_proxy.py,sha256=SLUf5udm1q5rFGixGbAOs4x03wO8pFcXdtMizW
47
53
  python_socks/async_/trio/_resolver.py,sha256=uqBoTkbYpwwESoph2SmXRUUHM_DsT7dALQDmKqp-sco,591
48
54
  python_socks/async_/trio/_stream.py,sha256=xunx_XUiwH1pBLQjWbkqq3P92SeXaRypPMPRYwHOsPg,1003
49
55
  python_socks/async_/trio/v2/__init__.py,sha256=3Bv4ukDEyxzxCX8JlgpTZR2Bbwq6Fu3csK0ZiX-XHXQ,106
50
- python_socks/async_/trio/v2/_chain.py,sha256=P0Ryqb0r4c4UwhtzhaTEx-5cxHhbm7dhTDzZCqxIOBo,867
51
- python_socks/async_/trio/v2/_connect.py,sha256=IymIbMoF_bDOgc1alCLeKahBqLDNKUxwpGGFreJv2Us,294
56
+ python_socks/async_/trio/v2/_chain.py,sha256=sf32gS-flmzVe60b83LtwOhbzvlm1s7gPlgIpAbW1hM,591
57
+ python_socks/async_/trio/v2/_connect.py,sha256=9B7cpLC9HqrXdW-61jA8hGRspHuIgaLTniZyCqpSiPE,379
52
58
  python_socks/async_/trio/v2/_factory.py,sha256=OAT9IbVy3vMNOhQFl-FYKnvGpzkQewmfVP9aUj6LlW4,317
53
- python_socks/async_/trio/v2/_proxy.py,sha256=rlSNH6mxNZtDlvvI_dpO_wSQkIV69XwN6-289U4b-mI,5260
59
+ python_socks/async_/trio/v2/_proxy.py,sha256=GOFTNECiNGBLevs9TyNIG99Umft6kxcYAbDxJ-rOp04,5590
54
60
  python_socks/async_/trio/v2/_stream.py,sha256=wGB7sDjRO1ywVNjF_DFgdF2orjD3zrh8dPSmW9aBEV0,1475
55
61
  python_socks/sync/__init__.py,sha256=Ju2_K1niNf50ijQtUk_LuY_QPexl4EWsFB9j4iPO3Z4,381
56
62
  python_socks/sync/_chain.py,sha256=TJeIQmvCw5Z0slBQOD0V9mibC5jbM9pDD_xjlyYgHFs,804
@@ -59,13 +65,14 @@ python_socks/sync/_proxy.py,sha256=MMFA3qwAWUaOp_Cv8mxDbk4FvuRXjrwzSfRkGVyqGSU,3
59
65
  python_socks/sync/_resolver.py,sha256=2rf9-NdjRktYrab1Oyv9ZJLKByP95ysFmRE3TgjRCSA,547
60
66
  python_socks/sync/_stream.py,sha256=x01ovajA0DAjHkBCxpMeFaWYjns9BljgBQ-GGyBqrw4,818
61
67
  python_socks/sync/v2/__init__.py,sha256=3Bv4ukDEyxzxCX8JlgpTZR2Bbwq6Fu3csK0ZiX-XHXQ,106
62
- python_socks/sync/v2/_chain.py,sha256=j0dUfILIgApgy4OeNsBvew-zfB14fXFwG7YiSCPYWiw,869
68
+ python_socks/sync/v2/_chain.py,sha256=IRVMioTVWwxylZ8maD5Gqxhhgw4VyrG5vo_hAOuEn8Q,579
69
+ python_socks/sync/v2/_connect.py,sha256=eqMKsH2wVnGZhV24_t9QfsNhjbnKtnipj7wzSNctM3Q,410
63
70
  python_socks/sync/v2/_factory.py,sha256=DcFdIU0X7b14mRUB4dWJ49l_zQFoRlKfOOw7t27HBEw,315
64
- python_socks/sync/v2/_proxy.py,sha256=WncK8-lSJpH6oBWQaiRh3cidGXGAjswGxLJvnEvLEJw,5107
71
+ python_socks/sync/v2/_proxy.py,sha256=hhzgCTpRiIyqkRWJcjVZoI7nzjMxn4V-vWdBCiXLIMY,5234
65
72
  python_socks/sync/v2/_ssl_transport.py,sha256=MURwzvKu-S2-MI7o8KaZTvvBFOiiKIu5R0ERVIMvERE,6088
66
73
  python_socks/sync/v2/_stream.py,sha256=Jq89x1xmIX3L_v-WyS1nRTItjTnYTcDcfDblsANxfJI,1544
67
- python_socks-2.1.1.dist-info/LICENSE.txt,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
68
- python_socks-2.1.1.dist-info/METADATA,sha256=Y2w4kdCFvlJNvBWICmlqU53E_IeGv6AIOV-KmBBeLAo,7050
69
- python_socks-2.1.1.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
70
- python_socks-2.1.1.dist-info/top_level.txt,sha256=7qyDAVwjTZ0sIYG1iatFbE-SLpWhONjaoMQ0Ib2DX0Q,13
71
- python_socks-2.1.1.dist-info/RECORD,,
74
+ python_socks-2.3.0.dist-info/LICENSE.txt,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
75
+ python_socks-2.3.0.dist-info/METADATA,sha256=w-K_UJ2GTVIxb9f5S-yfmVeETkH-eSoNtQuPpDpe7bY,7050
76
+ python_socks-2.3.0.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
77
+ python_socks-2.3.0.dist-info/top_level.txt,sha256=7qyDAVwjTZ0sIYG1iatFbE-SLpWhONjaoMQ0Ib2DX0Q,13
78
+ python_socks-2.3.0.dist-info/RECORD,,