rapida-python 0.0.6__py3-none-any.whl → 0.0.7__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.
- rapida/values.py +111 -5
- rapida/version.py +1 -1
- {rapida_python-0.0.6.dist-info → rapida_python-0.0.7.dist-info}/METADATA +1 -1
- {rapida_python-0.0.6.dist-info → rapida_python-0.0.7.dist-info}/RECORD +6 -6
- {rapida_python-0.0.6.dist-info → rapida_python-0.0.7.dist-info}/WHEEL +0 -0
- {rapida_python-0.0.6.dist-info → rapida_python-0.0.7.dist-info}/top_level.txt +0 -0
rapida/values.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
author: prashant.srivastav
|
|
3
3
|
"""
|
|
4
4
|
import mimetypes
|
|
5
|
+
import re
|
|
5
6
|
|
|
6
7
|
from google.protobuf.any_pb2 import Any
|
|
7
8
|
from google.protobuf.wrappers_pb2 import StringValue as _StringValue, BytesValue, Int32Value, FloatValue
|
|
@@ -31,6 +32,71 @@ def StringValue(_in: str) -> Any:
|
|
|
31
32
|
return any_message
|
|
32
33
|
|
|
33
34
|
|
|
35
|
+
def FileValue(file_path: str) -> Any:
|
|
36
|
+
"""
|
|
37
|
+
Convert a file to a proto.Any message.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
file_path (str): Path to the file.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
any_pb2.Any: Packed proto.Any message containing the file data.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
FileNotFoundError: If the file does not exist.
|
|
47
|
+
IOError: If an error occurs while reading the file.
|
|
48
|
+
ValueError: If the file is empty or an error occurs while packing.
|
|
49
|
+
"""
|
|
50
|
+
if not os.path.isfile(file_path):
|
|
51
|
+
raise RapidaException(
|
|
52
|
+
code=400,
|
|
53
|
+
message=f"The file at {file_path} does not exist.",
|
|
54
|
+
source="local",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Check file type
|
|
58
|
+
mime_type, _ = mimetypes.guess_type(file_path)
|
|
59
|
+
if not mime_type:
|
|
60
|
+
raise RapidaException(
|
|
61
|
+
code=400,
|
|
62
|
+
message="The file is not a valid file type.",
|
|
63
|
+
source="local",
|
|
64
|
+
)
|
|
65
|
+
try:
|
|
66
|
+
# Read the file data
|
|
67
|
+
with open(file_path, "rb") as file:
|
|
68
|
+
file_data = file.read()
|
|
69
|
+
|
|
70
|
+
if not file_data:
|
|
71
|
+
raise RapidaException(
|
|
72
|
+
code=400,
|
|
73
|
+
message="The file is empty or invalid.",
|
|
74
|
+
source="local",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# Create a BytesValue protobuf message with the file data
|
|
78
|
+
bytes_value = BytesValue(value=file_data)
|
|
79
|
+
|
|
80
|
+
# Create an Any message and pack the BytesValue into it
|
|
81
|
+
any_message = Any()
|
|
82
|
+
any_message.Pack(bytes_value)
|
|
83
|
+
|
|
84
|
+
return any_message
|
|
85
|
+
|
|
86
|
+
except IOError as e:
|
|
87
|
+
raise RapidaException(
|
|
88
|
+
code=400,
|
|
89
|
+
message=f"An error occurred while reading the file: {e}",
|
|
90
|
+
source="local",
|
|
91
|
+
)
|
|
92
|
+
except ValueError as e:
|
|
93
|
+
raise RapidaException(
|
|
94
|
+
code=400,
|
|
95
|
+
message=f"Error packing the file data: {e}",
|
|
96
|
+
source="local",
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
34
100
|
def AudioValue(file_path: str) -> Any:
|
|
35
101
|
"""
|
|
36
102
|
Convert an audio file to a proto.Any message.
|
|
@@ -79,19 +145,19 @@ def AudioValue(file_path: str) -> Any:
|
|
|
79
145
|
# Create an Any message and pack the BytesValue into it
|
|
80
146
|
any_message = Any()
|
|
81
147
|
# file_any = any_pb2.Any()
|
|
82
|
-
any_message.
|
|
148
|
+
any_message.Pack(audio_data)
|
|
83
149
|
|
|
84
150
|
return any_message
|
|
85
151
|
|
|
86
152
|
except IOError as e:
|
|
87
153
|
raise RapidaException(
|
|
88
|
-
code=
|
|
154
|
+
code=400,
|
|
89
155
|
message=f"An error occurred while reading the file: {e}",
|
|
90
156
|
source="local",
|
|
91
157
|
)
|
|
92
158
|
except ValueError as e:
|
|
93
159
|
raise RapidaException(
|
|
94
|
-
code=
|
|
160
|
+
code=400,
|
|
95
161
|
message=f"Error packing the file data: {e}",
|
|
96
162
|
source="local",
|
|
97
163
|
)
|
|
@@ -140,13 +206,13 @@ def ImageValue(file_path: str) -> Any:
|
|
|
140
206
|
return any_message
|
|
141
207
|
except IOError as e:
|
|
142
208
|
raise RapidaException(
|
|
143
|
-
code=
|
|
209
|
+
code=400,
|
|
144
210
|
message=f"An error occurred while reading the file: {e}",
|
|
145
211
|
source="local",
|
|
146
212
|
)
|
|
147
213
|
except ValueError as e:
|
|
148
214
|
raise RapidaException(
|
|
149
|
-
code=
|
|
215
|
+
code=400,
|
|
150
216
|
message=f"Error packing the file data: {e}",
|
|
151
217
|
source="local",
|
|
152
218
|
|
|
@@ -191,3 +257,43 @@ def NumberValue(number: float) -> Any:
|
|
|
191
257
|
any_message.Pack(number_value)
|
|
192
258
|
|
|
193
259
|
return any_message
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def URLValue(url: str) -> Any:
|
|
263
|
+
"""
|
|
264
|
+
Convert a URL to a proto.Any message.
|
|
265
|
+
|
|
266
|
+
Args:
|
|
267
|
+
url (str): The URL to convert.
|
|
268
|
+
|
|
269
|
+
Returns:
|
|
270
|
+
any_pb2.Any: Packed proto.Any message containing the URL.
|
|
271
|
+
|
|
272
|
+
Raises:
|
|
273
|
+
ValueError: If the URL is not valid.
|
|
274
|
+
"""
|
|
275
|
+
# Validate the URL
|
|
276
|
+
url_pattern = re.compile(
|
|
277
|
+
r'^(?:http|ftp)s?://' # http:// or https://
|
|
278
|
+
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain...
|
|
279
|
+
r'localhost|' # localhost...
|
|
280
|
+
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4
|
|
281
|
+
r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6
|
|
282
|
+
r'(?::\d+)?' # optional port
|
|
283
|
+
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
|
|
284
|
+
|
|
285
|
+
if not re.match(url_pattern, url):
|
|
286
|
+
raise RapidaException(
|
|
287
|
+
code=400,
|
|
288
|
+
message="The URL is not valid.",
|
|
289
|
+
source="local",
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
# Create a StringValue protobuf message with the URL
|
|
293
|
+
string_value = StringValue(value=url)
|
|
294
|
+
|
|
295
|
+
# Create an Any message and pack the StringValue into it
|
|
296
|
+
any_message = Any()
|
|
297
|
+
any_message.Pack(string_value)
|
|
298
|
+
|
|
299
|
+
return any_message
|
rapida/version.py
CHANGED
|
@@ -2,8 +2,8 @@ bin/__init__.py,sha256=uunvHyOaVic6mTNNF4PCIyo1VGRDH5PwAoLhf3I-lCA,35
|
|
|
2
2
|
rapida/__init__.py,sha256=bU2Cg_yR9BwIiyJpdJiJBoeLf9cjZBhemk3cSHd937A,634
|
|
3
3
|
rapida/rapida_client.py,sha256=pZhscA-pI9AuLKeSsfhZIv2fLr6Vp-Mnv5KUECe4dOA,5199
|
|
4
4
|
rapida/rapida_client_options.py,sha256=P_54uLDqVJnnMITDdNMEaNRjMghmVKgffT1bOQTpcz0,2382
|
|
5
|
-
rapida/values.py,sha256=
|
|
6
|
-
rapida/version.py,sha256=
|
|
5
|
+
rapida/values.py,sha256=0-CDpwlDky2blYhpR-KDSF2bMZ9d7U-m2PMJXN2Mp_s,8282
|
|
6
|
+
rapida/version.py,sha256=7DHKO57XerTxJZ9R_g3tLpPvIPxg_gAPk4SyTExGAiw,159
|
|
7
7
|
rapida/artifacts/__init__.py,sha256=uunvHyOaVic6mTNNF4PCIyo1VGRDH5PwAoLhf3I-lCA,35
|
|
8
8
|
rapida/artifacts/protos/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
rapida/artifacts/protos/common_pb2.py,sha256=exupVxsbHmpHCziFkgtebr-n1OzCOreYma57OY0HWEQ,11797
|
|
@@ -22,7 +22,7 @@ rapida/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
22
22
|
rapida/tests/test_rapida_client.py,sha256=4Fd7j_n8NGnoLfoITrN-owDxxoKLqmU9xzv6fjhlYbA,5751
|
|
23
23
|
rapida/tests/test_rapida_client_options.py,sha256=zOWRx9LTNF-9MYajWeFeIFWg_HUuAirH4EdffeH8W7M,3203
|
|
24
24
|
rapida/tests/test_values.py,sha256=pnXy4djs7b-xn5_W2SXSEJBtRBm9tbmucLKWyqSnmm8,1709
|
|
25
|
-
rapida_python-0.0.
|
|
26
|
-
rapida_python-0.0.
|
|
27
|
-
rapida_python-0.0.
|
|
28
|
-
rapida_python-0.0.
|
|
25
|
+
rapida_python-0.0.7.dist-info/METADATA,sha256=xlQzeli-mWmMue5vJqfK7chZ_7FRhzT4pZN6TnjxXm8,2335
|
|
26
|
+
rapida_python-0.0.7.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
|
27
|
+
rapida_python-0.0.7.dist-info/top_level.txt,sha256=046qVW6wPXCDmFm-V2YJcXQY0vApej2JLfv1NDKevoE,11
|
|
28
|
+
rapida_python-0.0.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|