portal 3.6.0__tar.gz → 3.7.0__tar.gz
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.
- {portal-3.6.0/portal.egg-info → portal-3.7.0}/PKG-INFO +1 -1
- {portal-3.6.0 → portal-3.7.0}/portal/__init__.py +1 -1
- {portal-3.6.0 → portal-3.7.0}/portal/client_socket.py +8 -1
- {portal-3.6.0 → portal-3.7.0}/portal/server_socket.py +16 -5
- {portal-3.6.0 → portal-3.7.0/portal.egg-info}/PKG-INFO +1 -1
- {portal-3.6.0 → portal-3.7.0}/tests/test_socket.py +11 -0
- {portal-3.6.0 → portal-3.7.0}/LICENSE +0 -0
- {portal-3.6.0 → portal-3.7.0}/MANIFEST.in +0 -0
- {portal-3.6.0 → portal-3.7.0}/README.md +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/batching.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/buffers.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/client.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/contextlib.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/packlib.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/poollib.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/process.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/server.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/sharray.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/thread.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal/utils.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal.egg-info/SOURCES.txt +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal.egg-info/dependency_links.txt +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal.egg-info/requires.txt +0 -0
- {portal-3.6.0 → portal-3.7.0}/portal.egg-info/top_level.txt +0 -0
- {portal-3.6.0 → portal-3.7.0}/pyproject.toml +0 -0
- {portal-3.6.0 → portal-3.7.0}/requirements.txt +0 -0
- {portal-3.6.0 → portal-3.7.0}/setup.cfg +0 -0
- {portal-3.6.0 → portal-3.7.0}/setup.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/tests/test_batching.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/tests/test_client.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/tests/test_errfile.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/tests/test_pack.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/tests/test_process.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/tests/test_server.py +0 -0
- {portal-3.6.0 → portal-3.7.0}/tests/test_thread.py +0 -0
@@ -31,6 +31,7 @@ class Options:
|
|
31
31
|
logging: bool = True
|
32
32
|
logging_color: str = 'yellow'
|
33
33
|
connect_wait: float = 0.1
|
34
|
+
handshake: str = 'portal_handshake'
|
34
35
|
|
35
36
|
|
36
37
|
class ClientSocket:
|
@@ -205,8 +206,9 @@ class ClientSocket:
|
|
205
206
|
try:
|
206
207
|
sock.settimeout(10)
|
207
208
|
sock.connect(addr)
|
208
|
-
sock.settimeout(0)
|
209
209
|
self._log('Connection established')
|
210
|
+
self._send_handshake(sock)
|
211
|
+
sock.settimeout(0)
|
210
212
|
return sock
|
211
213
|
except TimeoutError as e:
|
212
214
|
error = e
|
@@ -250,6 +252,11 @@ class ClientSocket:
|
|
250
252
|
|
251
253
|
return sock
|
252
254
|
|
255
|
+
def _send_handshake(self, sock):
|
256
|
+
buf = buffers.SendBuffer(self.options.handshake.encode('utf-8'))
|
257
|
+
while not buf.done():
|
258
|
+
buf.send(sock)
|
259
|
+
|
253
260
|
def _log(self, *args):
|
254
261
|
if not self.options.logging:
|
255
262
|
return
|
@@ -16,6 +16,7 @@ class Connection:
|
|
16
16
|
self.sock = sock
|
17
17
|
self.addr = addr
|
18
18
|
self.recvbuf = None
|
19
|
+
self.handshake = False
|
19
20
|
self.sendbufs = collections.deque()
|
20
21
|
|
21
22
|
def fileno(self):
|
@@ -32,6 +33,7 @@ class Options:
|
|
32
33
|
max_send_queue: int = 4096
|
33
34
|
logging: bool = True
|
34
35
|
logging_color: str = 'blue'
|
36
|
+
handshake: str = 'portal_handshake'
|
35
37
|
|
36
38
|
|
37
39
|
class ServerSocket:
|
@@ -157,11 +159,20 @@ class ServerSocket:
|
|
157
159
|
# - TimeoutError: [Errno 110] Connection timed out
|
158
160
|
self._disconnect(conn, e)
|
159
161
|
return
|
160
|
-
if conn.recvbuf.done():
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
if not conn.recvbuf.done():
|
163
|
+
return
|
164
|
+
if self.recvq.qsize() > self.options.max_recv_queue:
|
165
|
+
raise RuntimeError('Too many incoming messages enqueued')
|
166
|
+
message = conn.recvbuf.result()
|
167
|
+
conn.recvbuf = None
|
168
|
+
if not conn.handshake:
|
169
|
+
if message != self.options.handshake.encode('utf-8'):
|
170
|
+
e = ValueError(f"Handshake '{self.options.handshake}' expected")
|
171
|
+
self._disconnect(conn, e)
|
172
|
+
return
|
173
|
+
conn.handshake = True
|
174
|
+
else:
|
175
|
+
self.recvq.put((conn.addr, message))
|
165
176
|
|
166
177
|
def _disconnect(self, conn, e):
|
167
178
|
detail = f'{type(e).__name__}'
|
@@ -193,3 +193,14 @@ class TestSocket:
|
|
193
193
|
portal.Process(server, port),
|
194
194
|
portal.Process(client, port),
|
195
195
|
])
|
196
|
+
|
197
|
+
@pytest.mark.parametrize('ipv6', (False, True))
|
198
|
+
def test_wrong_protocol(self, ipv6):
|
199
|
+
port = portal.free_port()
|
200
|
+
server = portal.ServerSocket(port, ipv6=ipv6)
|
201
|
+
client = portal.ClientSocket(
|
202
|
+
port, ipv6=ipv6, autoconn=False, handshake='unknown_word')
|
203
|
+
client.connect()
|
204
|
+
with pytest.raises(portal.Disconnected):
|
205
|
+
client.recv()
|
206
|
+
server.close()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|