agi-med-common 3.5.4__py3-none-any.whl → 3.5.5__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,4 +1,4 @@
1
- __version__ = "3.5.4"
1
+ __version__ = "3.5.5"
2
2
 
3
3
  from .logger import LogLevelEnum, logger_init
4
4
  from .models import (
@@ -0,0 +1,39 @@
1
+ import string
2
+ from hashlib import md5
3
+ from pathlib import Path
4
+
5
+ ResourceId = str
6
+ ASCII_DIGITS = set(string.ascii_lowercase + string.digits)
7
+
8
+
9
+ def _validate_exist(files_dir):
10
+ if not files_dir.exists():
11
+ err = f"Failed to access file-storage directory: {files_dir}"
12
+ raise OSError(err)
13
+
14
+
15
+ def _validate_dtype(dtype: str):
16
+ if all(map(ASCII_DIGITS.__contains__, dtype)):
17
+ return
18
+ raise ValueError(f'Bad dtype: {dtype}')
19
+
20
+
21
+ class FileStorage:
22
+ def __init__(self, files_dir):
23
+ self.files_dir = Path(files_dir)
24
+ self.files_dir.mkdir(exist_ok=True)
25
+ _validate_exist(self.files_dir)
26
+
27
+ def upload(self, content: bytes, dtype: str) -> ResourceId | None:
28
+ _validate_dtype(dtype)
29
+ fname_hash = md5(content).hexdigest()
30
+ fname = f'{fname_hash}.{dtype}'
31
+ fpath = self.files_dir / fname
32
+ fpath.write_bytes(content)
33
+ return str(fpath)
34
+
35
+ def download(self, rid: ResourceId) -> bytes:
36
+ return Path(rid).read_bytes()
37
+
38
+ def is_valid(self, rid: ResourceId) -> bytes:
39
+ return Path(rid).exists() and Path(rid).is_file()
@@ -14,3 +14,4 @@ class TrackIdEnum(StrEnum):
14
14
  DUMMY = auto()
15
15
  COMMON_CONSULTATION = auto()
16
16
  FINANCIER = auto()
17
+ MULTIMODAL = auto()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agi_med_common
3
- Version: 3.5.4
3
+ Version: 3.5.5
4
4
  Summary: Сommon for agi-med team
5
5
  Author: AGI-MED-TEAM
6
6
  Requires-Python: >=3.11
@@ -1,4 +1,5 @@
1
- agi_med_common/__init__.py,sha256=xl4bes4OjoEwc3IBkPUrKT3tn4NdiUxKNT-3Swjtcgc,511
1
+ agi_med_common/__init__.py,sha256=vHBvgayIw-99w9ksvmaANazMbH2LZuv-T92HBbiNl7A,511
2
+ agi_med_common/file_storage.py,sha256=W6MOWBrO20y-xnW3FIR8vABK2PazRk3-Jm853mVXttk,1115
2
3
  agi_med_common/utils.py,sha256=4GV1yNZiRG3KYOh859dvOZI899z7_s_YN3aXzthMgwU,399
3
4
  agi_med_common/validators.py,sha256=R678gjPp-5XbnocRuEtdOQgJyCCOurxwaOe2nT04kSg,705
4
5
  agi_med_common/xml_parser.py,sha256=VvLIX_XCZao9i0qqpTVx8nx0vbFXSe8pEbdJdXnj97g,568
@@ -22,8 +23,8 @@ agi_med_common/models/enums/moderation_label_enum.py,sha256=lbGG4Pu7cQp57uEyQEpt
22
23
  agi_med_common/models/enums/mtrs_label_enum.py,sha256=6emBndt3SCsQVZZFKQYCV2_iyjjmZEhwejJKJu39ZAw,257
23
24
  agi_med_common/models/enums/mtrs_xml_tag_enum.py,sha256=6OxuRsrx4b2uBjfrBgm4Y789Ly337_mQXL9VPRCpLyg,273
24
25
  agi_med_common/models/enums/state_enum.py,sha256=p7XhDxBxPeeSgbLWitq6JpJLKntS3XMHon_EevbnhEs,163
25
- agi_med_common/models/enums/track_id_enum.py,sha256=P2b89MP7E3ePZ8bZR2Db12su_Z6r6K45e3090fugFUY,477
26
- agi_med_common-3.5.4.dist-info/METADATA,sha256=SCUgVS-kUV9BeGrpSdcVUMQIAJCXgdbk0GJxTGhWHFM,520
27
- agi_med_common-3.5.4.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
28
- agi_med_common-3.5.4.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
29
- agi_med_common-3.5.4.dist-info/RECORD,,
26
+ agi_med_common/models/enums/track_id_enum.py,sha256=KM4DbJ6fzK4xPSghKBaTdAhz_SlTSLxJvnKJoMjc9QE,501
27
+ agi_med_common-3.5.5.dist-info/METADATA,sha256=lVIYXrkwvbdsgSzL5IPKFK-ZahrgODJQXx828rXdgf0,520
28
+ agi_med_common-3.5.5.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
29
+ agi_med_common-3.5.5.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
30
+ agi_med_common-3.5.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (78.0.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5