synapse-sdk 1.0.0a43__py3-none-any.whl → 1.0.0a44__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.

Potentially problematic release.


This version of synapse-sdk might be problematic. Click here for more details.

synapse_sdk/utils/http.py CHANGED
@@ -3,6 +3,7 @@ import os
3
3
  import tempfile
4
4
  import threading
5
5
  import time
6
+ import uuid
6
7
  from contextlib import contextmanager
7
8
  from http.server import HTTPServer, SimpleHTTPRequestHandler
8
9
 
@@ -17,23 +18,32 @@ class SingleFileHttpServer(SimpleHTTPRequestHandler):
17
18
  regardless of the request path.
18
19
  """
19
20
 
20
- def __init__(self, *args, file_path=None, content_type=None, **kwargs):
21
+ def __init__(self, *args, file_path=None, content_type=None, random_path=None, **kwargs):
21
22
  self.file_path = file_path
22
23
  self.content_type = content_type
24
+ self.random_path = random_path
23
25
  super().__init__(*args, **kwargs)
24
26
 
25
27
  def do_GET(self):
26
28
  """Handle GET requests by serving the single file."""
27
29
  try:
28
- # Always serve the specified file regardless of the path requested
29
- self.send_response(200)
30
- if self.content_type:
31
- self.send_header('Content-type', self.content_type)
32
- self.send_header('Content-Length', str(os.path.getsize(self.file_path)))
33
- self.end_headers()
34
-
35
- with open(self.file_path, 'rb') as file:
36
- self.wfile.write(file.read())
30
+ # Check if the path matches our random path
31
+ if self.random_path and self.path == f"/{self.random_path}":
32
+ self.send_response(200)
33
+ if self.content_type:
34
+ self.send_header('Content-type', self.content_type)
35
+ self.send_header('Content-Length', str(os.path.getsize(self.file_path)))
36
+ self.end_headers()
37
+
38
+ with open(self.file_path, 'rb') as file:
39
+ self.wfile.write(file.read())
40
+ elif self.path == "/":
41
+ # Redirect root to the random path
42
+ self.send_response(302)
43
+ self.send_header('Location', f"/{self.random_path}")
44
+ self.end_headers()
45
+ else:
46
+ self.send_error(404, "File not found")
37
47
 
38
48
  except Exception as e:
39
49
  self.send_error(500, str(e))
@@ -68,8 +78,11 @@ def temp_file_server(image=None, file_path=None, format='JPEG', host='0.0.0.0',
68
78
  port = get_available_ports_host(start_port=8991, end_port=8999)
69
79
 
70
80
  temp_dir = None
81
+ temp_file_path = None
71
82
 
72
83
  try:
84
+ random_filename = f"{uuid.uuid4().hex}"
85
+
73
86
  if image is not None:
74
87
  temp_dir = tempfile.mkdtemp()
75
88
  ext_map = {'JPEG': '.jpg', 'PNG': '.png', 'GIF': '.gif', 'WEBP': '.webp'}
@@ -82,9 +95,14 @@ def temp_file_server(image=None, file_path=None, format='JPEG', host='0.0.0.0',
82
95
  temp_file_path = os.path.join(temp_dir, f'temp_image{ext}')
83
96
  image.save(temp_file_path, format=format)
84
97
  file_path = temp_file_path
98
+ random_filename += ext
99
+ else:
100
+ _, ext = os.path.splitext(file_path)
101
+ random_filename += ext
85
102
 
86
103
  def handler(*args, **kwargs):
87
- return SingleFileHttpServer(*args, file_path=file_path, content_type=content_type, **kwargs)
104
+ return SingleFileHttpServer(*args, file_path=file_path, content_type=content_type,
105
+ random_path=random_filename, **kwargs)
88
106
 
89
107
  server = HTTPServer((host, port), handler)
90
108
 
@@ -92,10 +110,9 @@ def temp_file_server(image=None, file_path=None, format='JPEG', host='0.0.0.0',
92
110
  server_thread.daemon = True
93
111
  server_thread.start()
94
112
 
95
- url = f'http://localhost:{port}'
113
+ url = f'http://localhost:{port}/{random_filename}'
96
114
 
97
- timeout = time.time() + 10
98
- while time.time() < timeout:
115
+ while True:
99
116
  try:
100
117
  response = requests.get(url)
101
118
  if response.status_code == 200:
@@ -103,7 +120,7 @@ def temp_file_server(image=None, file_path=None, format='JPEG', host='0.0.0.0',
103
120
  except requests.exceptions.ConnectionError:
104
121
  pass
105
122
  time.sleep(0.01)
106
-
123
+
107
124
  try:
108
125
  yield url
109
126
  finally:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a43
3
+ Version: 1.0.0a44
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -120,7 +120,7 @@ synapse_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
120
120
  synapse_sdk/utils/dataset.py,sha256=zWTzFmv589izFr62BDuApi3r5FpTsdm-5AmriC0AEdM,1865
121
121
  synapse_sdk/utils/debug.py,sha256=F7JlUwYjTFZAMRbBqKm6hxOIz-_IXYA8lBInOS4jbS4,100
122
122
  synapse_sdk/utils/file.py,sha256=wWBQAx0cB5a-fjfRMeJV-KjBil1ZyKRz-vXno3xBSoo,6834
123
- synapse_sdk/utils/http.py,sha256=L0YZIfgg2GOexqA1dKihae1-MagDRYIMJn2ilVNuj-8,4076
123
+ synapse_sdk/utils/http.py,sha256=pQ_xiDz3bIR_XSfT3muNn3V2petu7r4uR1kv0fXUndM,4785
124
124
  synapse_sdk/utils/module_loading.py,sha256=chHpU-BZjtYaTBD_q0T7LcKWtqKvYBS4L0lPlKkoMQ8,1020
125
125
  synapse_sdk/utils/network.py,sha256=WI8qn6KlKpHdMi45V57ofKJB8zusJrbQsxT74LwVfsY,1000
126
126
  synapse_sdk/utils/string.py,sha256=rEwuZ9SAaZLcQ8TYiwNKr1h2u4CfnrQx7SUL8NWmChg,216
@@ -134,9 +134,9 @@ synapse_sdk/utils/storage/providers/__init__.py,sha256=x7RGwZryT2FpVxS7fGWryRVpq
134
134
  synapse_sdk/utils/storage/providers/gcp.py,sha256=i2BQCu1Kej1If9SuNr2_lEyTcr5M_ncGITZrL0u5wEA,363
135
135
  synapse_sdk/utils/storage/providers/s3.py,sha256=W94rQvhGRXti3R4mYP7gmU5pcyCQpGFIBLvxxqLVdRM,2231
136
136
  synapse_sdk/utils/storage/providers/sftp.py,sha256=_8s9hf0JXIO21gvm-JVS00FbLsbtvly4c-ETLRax68A,1426
137
- synapse_sdk-1.0.0a43.dist-info/licenses/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
138
- synapse_sdk-1.0.0a43.dist-info/METADATA,sha256=btu9DJL27zAyQTixfosy2HdnA-EkfK5KVgXaLR4F2CM,1203
139
- synapse_sdk-1.0.0a43.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
140
- synapse_sdk-1.0.0a43.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
141
- synapse_sdk-1.0.0a43.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
142
- synapse_sdk-1.0.0a43.dist-info/RECORD,,
137
+ synapse_sdk-1.0.0a44.dist-info/licenses/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
138
+ synapse_sdk-1.0.0a44.dist-info/METADATA,sha256=gMEVtQmAmnqDdMgHzixO5U5cN6ANhpMOI94FvRuN-fk,1203
139
+ synapse_sdk-1.0.0a44.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
140
+ synapse_sdk-1.0.0a44.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
141
+ synapse_sdk-1.0.0a44.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
142
+ synapse_sdk-1.0.0a44.dist-info/RECORD,,