agi-med-common 4.2.0__py3-none-any.whl → 4.2.2__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.
- agi_med_common/__init__.py +2 -2
- agi_med_common/file_storage.py +7 -3
- agi_med_common/validators.py +11 -1
- {agi_med_common-4.2.0.dist-info → agi_med_common-4.2.2.dist-info}/METADATA +1 -1
- {agi_med_common-4.2.0.dist-info → agi_med_common-4.2.2.dist-info}/RECORD +7 -7
- {agi_med_common-4.2.0.dist-info → agi_med_common-4.2.2.dist-info}/WHEEL +0 -0
- {agi_med_common-4.2.0.dist-info → agi_med_common-4.2.2.dist-info}/top_level.txt +0 -0
agi_med_common/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "4.2.
|
1
|
+
__version__ = "4.2.2"
|
2
2
|
|
3
3
|
from .logger import LogLevelEnum, logger_init
|
4
4
|
from .models import (
|
@@ -16,6 +16,6 @@ from .models import (
|
|
16
16
|
from .file_storage import FileStorage
|
17
17
|
from .models import DiagnosticsXMLTagEnum, MTRSXMLTagEnum, DoctorChoiceXMLTagEnum
|
18
18
|
from .utils import make_session_id, read_json
|
19
|
-
from .validators import ExistingPath, ExistingFile, StrNotEmpty, Prompt
|
19
|
+
from .validators import ExistingPath, ExistingFile, ExistingDir, StrNotEmpty, SecretStrNotEmpty, Prompt, Message
|
20
20
|
from .xml_parser import XMLParser
|
21
21
|
from .parallel_map import parallel_map
|
agi_med_common/file_storage.py
CHANGED
@@ -18,6 +18,12 @@ def _validate_dtype(dtype: str):
|
|
18
18
|
raise ValueError(f'Bad dtype: {dtype}')
|
19
19
|
|
20
20
|
|
21
|
+
def generate_fname(content, dtype):
|
22
|
+
fname_hash = md5(content).hexdigest()
|
23
|
+
fname = f'{fname_hash}.{dtype}'
|
24
|
+
return fname
|
25
|
+
|
26
|
+
|
21
27
|
class FileStorage:
|
22
28
|
def __init__(self, files_dir):
|
23
29
|
self.files_dir = Path(files_dir)
|
@@ -25,9 +31,7 @@ class FileStorage:
|
|
25
31
|
_validate_exist(self.files_dir)
|
26
32
|
|
27
33
|
def _generate_fname_path(self, content, dtype):
|
28
|
-
|
29
|
-
fname = f'{fname_hash}.{dtype}'
|
30
|
-
fpath = self.files_dir / fname
|
34
|
+
fpath = self.files_dir / generate_fname(content, dtype)
|
31
35
|
return fpath
|
32
36
|
|
33
37
|
def upload_maybe(
|
agi_med_common/validators.py
CHANGED
@@ -2,9 +2,11 @@ import os
|
|
2
2
|
import re
|
3
3
|
from pathlib import Path
|
4
4
|
from typing import Annotated, TypeVar
|
5
|
-
from pydantic import AfterValidator
|
5
|
+
from pydantic import AfterValidator, SecretStr
|
6
6
|
|
7
7
|
|
8
|
+
Message = Annotated[str, AfterValidator(lambda msg: msg.replace("\\n", "\n"))]
|
9
|
+
|
8
10
|
PathLike = str | os.PathLike[str] | Path
|
9
11
|
|
10
12
|
|
@@ -20,8 +22,15 @@ def validate_existing_file(filepath: PathLike) -> PathLike:
|
|
20
22
|
return filepath
|
21
23
|
|
22
24
|
|
25
|
+
def validate_existing_dir(filepath: PathLike) -> PathLike:
|
26
|
+
if not os.path.isdir(filepath):
|
27
|
+
raise ValueError(f"Path {filepath} is not file")
|
28
|
+
return filepath
|
29
|
+
|
30
|
+
|
23
31
|
ExistingPath = Annotated[Path, AfterValidator(validate_existing_path)]
|
24
32
|
ExistingFile = Annotated[Path, AfterValidator(validate_existing_file)]
|
33
|
+
ExistingDir = Annotated[Path, AfterValidator(validate_existing_dir)]
|
25
34
|
|
26
35
|
|
27
36
|
def validate_not_empty(text: any) -> any:
|
@@ -31,6 +40,7 @@ def validate_not_empty(text: any) -> any:
|
|
31
40
|
|
32
41
|
|
33
42
|
StrNotEmpty = Annotated[str, AfterValidator(validate_not_empty)]
|
43
|
+
SecretStrNotEmpty = Annotated[SecretStr, AfterValidator(validate_not_empty)]
|
34
44
|
|
35
45
|
|
36
46
|
def validate_prompt(prompt: str, prompt_required_keys: set[str]) -> str:
|
@@ -1,8 +1,8 @@
|
|
1
|
-
agi_med_common/__init__.py,sha256=
|
2
|
-
agi_med_common/file_storage.py,sha256=
|
1
|
+
agi_med_common/__init__.py,sha256=XO04WfJZPQAsLHHRTU0U-S2lKAItsZNO9TlRrlubhjM,633
|
2
|
+
agi_med_common/file_storage.py,sha256=F31pzqkVtWSqcCqShJCrJc78iU4VmNeAY0p4eUbOPNI,1574
|
3
3
|
agi_med_common/parallel_map.py,sha256=Qx6xe7DqlEUDpSucp5Hm8r9y9Iquwh9JvX7lOqHhnOw,921
|
4
4
|
agi_med_common/utils.py,sha256=5iurKl5d1zZ_cN4yqtc0_FhrwuNBcDurbWilu28_saE,325
|
5
|
-
agi_med_common/validators.py,sha256=
|
5
|
+
agi_med_common/validators.py,sha256=vMoPN42XzC8re-zdjekk5_lNQYHuTiAWD56YLvj2Z2w,2824
|
6
6
|
agi_med_common/xml_parser.py,sha256=VvLIX_XCZao9i0qqpTVx8nx0vbFXSe8pEbdJdXnj97g,568
|
7
7
|
agi_med_common/logger/__init__.py,sha256=RW_0VZtbeJ4RsLqUXZUQWl5CtV9g840rU7qRlf5u49E,96
|
8
8
|
agi_med_common/logger/log_level_enum.py,sha256=lWuSMho9I0v_xf1RuwpERx5o8NJXaavjwxSdh8fxMqE,477
|
@@ -23,7 +23,7 @@ agi_med_common/models/enums/moderation_label_enum.py,sha256=lbGG4Pu7cQp57uEyQEpt
|
|
23
23
|
agi_med_common/models/enums/mtrs_label_enum.py,sha256=6emBndt3SCsQVZZFKQYCV2_iyjjmZEhwejJKJu39ZAw,257
|
24
24
|
agi_med_common/models/enums/mtrs_xml_tag_enum.py,sha256=6OxuRsrx4b2uBjfrBgm4Y789Ly337_mQXL9VPRCpLyg,273
|
25
25
|
agi_med_common/models/enums/track_id_enum.py,sha256=N3KUd97a4xDet_NKZ5URm0qWAAv3ts1l_foOjdlGY4c,532
|
26
|
-
agi_med_common-4.2.
|
27
|
-
agi_med_common-4.2.
|
28
|
-
agi_med_common-4.2.
|
29
|
-
agi_med_common-4.2.
|
26
|
+
agi_med_common-4.2.2.dist-info/METADATA,sha256=IvEpNyZI8ToS8muCz2RxwjygoKP5HyBqB2jjQ8zacgc,546
|
27
|
+
agi_med_common-4.2.2.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
28
|
+
agi_med_common-4.2.2.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
|
29
|
+
agi_med_common-4.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|