portal 3.5.1__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.5.1/portal.egg-info → portal-3.7.0}/PKG-INFO +2 -2
- {portal-3.5.1 → portal-3.7.0}/README.md +1 -1
- {portal-3.5.1 → portal-3.7.0}/portal/__init__.py +1 -1
- {portal-3.5.1 → portal-3.7.0}/portal/buffers.py +3 -3
- {portal-3.5.1 → portal-3.7.0}/portal/client_socket.py +8 -1
- {portal-3.5.1 → portal-3.7.0}/portal/server.py +2 -0
- {portal-3.5.1 → portal-3.7.0}/portal/server_socket.py +16 -5
- {portal-3.5.1 → portal-3.7.0/portal.egg-info}/PKG-INFO +2 -2
- {portal-3.5.1 → portal-3.7.0}/tests/test_socket.py +11 -0
- {portal-3.5.1 → portal-3.7.0}/LICENSE +0 -0
- {portal-3.5.1 → portal-3.7.0}/MANIFEST.in +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/batching.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/client.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/contextlib.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/packlib.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/poollib.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/process.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/sharray.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/thread.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal/utils.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal.egg-info/SOURCES.txt +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal.egg-info/dependency_links.txt +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal.egg-info/requires.txt +0 -0
- {portal-3.5.1 → portal-3.7.0}/portal.egg-info/top_level.txt +0 -0
- {portal-3.5.1 → portal-3.7.0}/pyproject.toml +0 -0
- {portal-3.5.1 → portal-3.7.0}/requirements.txt +0 -0
- {portal-3.5.1 → portal-3.7.0}/setup.cfg +0 -0
- {portal-3.5.1 → portal-3.7.0}/setup.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/tests/test_batching.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/tests/test_client.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/tests/test_errfile.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/tests/test_pack.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/tests/test_process.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/tests/test_server.py +0 -0
- {portal-3.5.1 → portal-3.7.0}/tests/test_thread.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: portal
|
3
|
-
Version: 3.
|
3
|
+
Version: 3.7.0
|
4
4
|
Summary: Fast and reliable distributed systems in Python
|
5
5
|
Home-page: http://github.com/danijar/portal
|
6
6
|
Author: Danijar Hafner
|
@@ -58,7 +58,7 @@ def server():
|
|
58
58
|
|
59
59
|
def client():
|
60
60
|
import portal
|
61
|
-
client = portal.Client('localhost'
|
61
|
+
client = portal.Client('localhost:2222')
|
62
62
|
future = client.add(12, 42)
|
63
63
|
result = future.result()
|
64
64
|
print(result) # 54
|
@@ -17,7 +17,7 @@ class SendBuffer:
|
|
17
17
|
assert all(len(x) for x in buffers)
|
18
18
|
assert 1 <= length, length
|
19
19
|
assert not maxsize or length <= length, (length, maxsize)
|
20
|
-
lenbuf = length.to_bytes(
|
20
|
+
lenbuf = length.to_bytes(8, 'little', signed=False)
|
21
21
|
self.buffers = [lenbuf, *buffers]
|
22
22
|
self.remaining = collections.deque(self.buffers)
|
23
23
|
self.pos = 0
|
@@ -64,10 +64,10 @@ class RecvBuffer:
|
|
64
64
|
|
65
65
|
def recv(self, sock):
|
66
66
|
if self.buffer is None:
|
67
|
-
part = sock.recv(
|
67
|
+
part = sock.recv(8 - len(self.lenbuf))
|
68
68
|
self.lenbuf += part
|
69
69
|
size = len(part)
|
70
|
-
if len(self.lenbuf) ==
|
70
|
+
if len(self.lenbuf) == 8:
|
71
71
|
length = int.from_bytes(self.lenbuf, 'little', signed=False)
|
72
72
|
assert 1 <= length <= self.maxsize, (1, length, self.maxsize)
|
73
73
|
# We use Numpy to allocate uninitialized memory because Python's
|
@@ -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__}'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: portal
|
3
|
-
Version: 3.
|
3
|
+
Version: 3.7.0
|
4
4
|
Summary: Fast and reliable distributed systems in Python
|
5
5
|
Home-page: http://github.com/danijar/portal
|
6
6
|
Author: Danijar Hafner
|
@@ -58,7 +58,7 @@ def server():
|
|
58
58
|
|
59
59
|
def client():
|
60
60
|
import portal
|
61
|
-
client = portal.Client('localhost'
|
61
|
+
client = portal.Client('localhost:2222')
|
62
62
|
future = client.add(12, 42)
|
63
63
|
result = future.result()
|
64
64
|
print(result) # 54
|
@@ -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
|