agi-med-common 4.2.1__py3-none-any.whl → 4.2.3__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__ = "4.2.1"
1
+ __version__ = "4.2.3"
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, SecretStrNotEmpty, 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
@@ -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
- fname_hash = md5(content).hexdigest()
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(
@@ -51,3 +55,6 @@ class FileStorage:
51
55
 
52
56
  def is_valid(self, rid: ResourceId) -> bytes:
53
57
  return Path(rid).exists() and Path(rid).is_file()
58
+
59
+ def get_dtype(self, rid: ResourceId) -> str:
60
+ return rid.rsplit('.')[-1]
@@ -5,6 +5,8 @@ from typing import Annotated, TypeVar
5
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agi_med_common
3
- Version: 4.2.1
3
+ Version: 4.2.3
4
4
  Summary: Сommon for agi-med team
5
5
  Author: AGI-MED-TEAM
6
6
  Requires-Python: >=3.11
@@ -1,8 +1,8 @@
1
- agi_med_common/__init__.py,sha256=kSY51g91X68T7k39gwISEOrDa3Qi9IWCnN3wgr0VQ-E,611
2
- agi_med_common/file_storage.py,sha256=uyZE3ePKrbVLNVcvxw9lbgumy1UPwDGIwQMs1Bd8HFI,1502
1
+ agi_med_common/__init__.py,sha256=C9Zp4og7k51EB1Rg6lnLyGcUvVe9mWhbV8RMR1e_US4,633
2
+ agi_med_common/file_storage.py,sha256=4GW0CU0YtVzWmxV6vGjZg0DfyEgjlrgLRsZ7cEP-6Qk,1659
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=PGP_ztcS3pOnVCIR9LVBOaC4F3u_JePrKKUO4vp214E,2501
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.1.dist-info/METADATA,sha256=1Gfop4JXcz0yraYXd7XXydl5DY9vGmd6Da5EnYQVANc,546
27
- agi_med_common-4.2.1.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
28
- agi_med_common-4.2.1.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
29
- agi_med_common-4.2.1.dist-info/RECORD,,
26
+ agi_med_common-4.2.3.dist-info/METADATA,sha256=XwEdymZhto-w644Xcf_2awerhrCblh2d3UFuHho81BM,546
27
+ agi_med_common-4.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ agi_med_common-4.2.3.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
29
+ agi_med_common-4.2.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5