mmar-mapi 1.0.4__py3-none-any.whl → 1.0.6__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 mmar-mapi might be problematic. Click here for more details.
- mmar_mapi/file_storage.py +24 -11
- mmar_mapi/models/chat.py +1 -1
- {mmar_mapi-1.0.4.dist-info → mmar_mapi-1.0.6.dist-info}/METADATA +1 -1
- {mmar_mapi-1.0.4.dist-info → mmar_mapi-1.0.6.dist-info}/RECORD +6 -6
- {mmar_mapi-1.0.4.dist-info → mmar_mapi-1.0.6.dist-info}/WHEEL +0 -0
- {mmar_mapi-1.0.4.dist-info → mmar_mapi-1.0.6.dist-info}/licenses/LICENSE +0 -0
mmar_mapi/file_storage.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import string
|
|
3
|
+
from datetime import datetime
|
|
2
4
|
from hashlib import md5
|
|
3
5
|
from pathlib import Path
|
|
4
6
|
from zipfile import ZipFile, is_zipfile
|
|
5
7
|
|
|
6
|
-
|
|
7
8
|
ResourceId = str
|
|
8
9
|
ASCII_DIGITS = set(string.ascii_lowercase + string.digits)
|
|
9
10
|
SUFFIX_DIR = ".dir"
|
|
11
|
+
SUFFIX_METADATA = ".metadata"
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
def _validate_exist(files_dir):
|
|
@@ -37,20 +39,31 @@ class FileStorage:
|
|
|
37
39
|
fpath = self.files_dir / generate_fname(content, dtype)
|
|
38
40
|
return fpath
|
|
39
41
|
|
|
40
|
-
def upload_maybe(self, content: bytes | None,
|
|
42
|
+
def upload_maybe(self, content: bytes | str | None, fname: str) -> ResourceId | None:
|
|
41
43
|
if not content:
|
|
42
44
|
return None
|
|
43
|
-
resource_id = self.upload(content,
|
|
45
|
+
resource_id = self.upload(content, fname)
|
|
44
46
|
return resource_id
|
|
45
47
|
|
|
46
|
-
def upload(self, content: bytes | str,
|
|
47
|
-
_validate_dtype(dtype)
|
|
48
|
+
def upload(self, content: bytes | str, fname: str) -> ResourceId:
|
|
48
49
|
if isinstance(content, str):
|
|
49
50
|
content = content.encode()
|
|
51
|
+
|
|
52
|
+
dtype = fname.rsplit(".", 1)[-1]
|
|
53
|
+
_validate_dtype(dtype)
|
|
50
54
|
fpath = self._generate_fname_path(content, dtype)
|
|
51
55
|
fpath.write_bytes(content)
|
|
56
|
+
|
|
57
|
+
fpath_md = fpath.with_suffix(SUFFIX_METADATA)
|
|
58
|
+
update_date = f"{datetime.now():%Y-%m-%d--%H-%M-%S}"
|
|
59
|
+
metadata = {"fname": fname, "update_date": update_date, "size": len(content)}
|
|
60
|
+
fpath_md.write_text(json.dumps(metadata, ensure_ascii=False))
|
|
61
|
+
|
|
52
62
|
return str(fpath)
|
|
53
63
|
|
|
64
|
+
async def upload_async(self, content: bytes | str, fname: str) -> ResourceId:
|
|
65
|
+
return self.upload(content, fname)
|
|
66
|
+
|
|
54
67
|
def upload_dir(self, resource_ids: list[ResourceId]) -> ResourceId:
|
|
55
68
|
content = "\n".join(resource_ids)
|
|
56
69
|
res = self.upload(content, "dir")
|
|
@@ -59,6 +72,9 @@ class FileStorage:
|
|
|
59
72
|
def download(self, resource_id: ResourceId) -> bytes:
|
|
60
73
|
return Path(resource_id).read_bytes()
|
|
61
74
|
|
|
75
|
+
async def download_async(self, resource_id: ResourceId) -> bytes:
|
|
76
|
+
return self.download(resource_id)
|
|
77
|
+
|
|
62
78
|
def download_text(self, resource_id: ResourceId) -> str:
|
|
63
79
|
return Path(resource_id).read_text(encoding="utf-8")
|
|
64
80
|
|
|
@@ -90,7 +106,7 @@ class FileStorage:
|
|
|
90
106
|
return resource_id and resource_id.rsplit(".")[-1]
|
|
91
107
|
|
|
92
108
|
def unzip_file(self, resource_id: str) -> ResourceId:
|
|
93
|
-
"""
|
|
109
|
+
"""takes resource_id which refer to zip-archive, unpacks it and returns directory ResourceId with content of zip-archive"""
|
|
94
110
|
path = self._get_path(resource_id)
|
|
95
111
|
if not path:
|
|
96
112
|
raise ValueError(f"Not found path: {resource_id}")
|
|
@@ -99,15 +115,12 @@ class FileStorage:
|
|
|
99
115
|
|
|
100
116
|
resource_ids = []
|
|
101
117
|
|
|
102
|
-
with ZipFile(path, mode=
|
|
103
|
-
files_info = zip_file.filelist
|
|
104
|
-
|
|
118
|
+
with ZipFile(path, mode="r") as zip_file:
|
|
105
119
|
for file_info in zip_file.filelist:
|
|
106
|
-
file_dtype = file_info.filename.rsplit(
|
|
120
|
+
file_dtype = file_info.filename.rsplit(".")[-1]
|
|
107
121
|
file_bytes = zip_file.read(file_info)
|
|
108
122
|
rid = self.upload(file_bytes, file_dtype)
|
|
109
123
|
resource_ids.append(rid)
|
|
110
124
|
|
|
111
125
|
res = self.upload_dir(resource_ids)
|
|
112
126
|
return res
|
|
113
|
-
|
mmar_mapi/models/chat.py
CHANGED
|
@@ -229,7 +229,7 @@ def make_content(
|
|
|
229
229
|
resource_id: str | None = None,
|
|
230
230
|
command: dict | None = None,
|
|
231
231
|
widget: Widget | None = None,
|
|
232
|
-
content: Content | None = None
|
|
232
|
+
content: Content | None = None,
|
|
233
233
|
) -> Content:
|
|
234
234
|
resource_id = (resource_id or None) and {"type": "resource_id", "resource_id": resource_id}
|
|
235
235
|
command = (command or None) and {"type": "command", "command": command}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
mmar_mapi/__init__.py,sha256=cj3McZDG8zU1nLSMjwtVHG0u99xN7LaNLW90d4tK7Io,613
|
|
2
2
|
mmar_mapi/api.py,sha256=C9Sr8dISvf51xfEznPjccI_odaG4coQE3HI_0jVpjMQ,1677
|
|
3
|
-
mmar_mapi/file_storage.py,sha256=
|
|
3
|
+
mmar_mapi/file_storage.py,sha256=GbahBabBdAKjlAnv1MszERUxxZyA9HGMiR9tz2a9dgY,4409
|
|
4
4
|
mmar_mapi/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
mmar_mapi/models/base.py,sha256=mKtXV2x51XVj7W-et9tjGcPMDUUUMelW-BywMgFc2p0,411
|
|
6
6
|
mmar_mapi/models/base_config_models/__init__.py,sha256=KjS_bSCka8BOMsigwcIML-e6eNB2ouMU6gxlhRmzeuY,44
|
|
7
7
|
mmar_mapi/models/base_config_models/gigachat_config.py,sha256=QvKTnp0VioXzd3_PUgNBeYx5RDTZT-45j-Ll-wXEI_o,421
|
|
8
|
-
mmar_mapi/models/chat.py,sha256=
|
|
8
|
+
mmar_mapi/models/chat.py,sha256=sAYuudA--i7qVfEERy5K5wmAkIFAjn6vUrKRT_BmfIE,12480
|
|
9
9
|
mmar_mapi/models/chat_item.py,sha256=ZfCKvTqr7gpuJSAuHVxWRnlTefRwki_IVNA2N_CXGdg,5557
|
|
10
10
|
mmar_mapi/models/enums.py,sha256=J-GNpql9MCnKnWiV9aJRQGI-pAybvV86923RZs99grA,1006
|
|
11
11
|
mmar_mapi/models/tracks.py,sha256=HKDp-BX1p7AlDfSEKfOKCu0TRSK9cD4Dmq1vJt8oRjw,307
|
|
@@ -13,7 +13,7 @@ mmar_mapi/models/widget.py,sha256=KXSP3d4yQNeificMfzRxROdByw9IkxwCjkDD0kc7tcQ,70
|
|
|
13
13
|
mmar_mapi/type_union.py,sha256=diwmzcnbqkpGFckPHNw9o8zyQ955mOGNvhTlcBJ0RMI,1905
|
|
14
14
|
mmar_mapi/utils.py,sha256=hcKJVslvTBLw2vjZ9zcKZxh_tqk48obHcVs_i3Rxn3M,112
|
|
15
15
|
mmar_mapi/xml_parser.py,sha256=VvLIX_XCZao9i0qqpTVx8nx0vbFXSe8pEbdJdXnj97g,568
|
|
16
|
-
mmar_mapi-1.0.
|
|
17
|
-
mmar_mapi-1.0.
|
|
18
|
-
mmar_mapi-1.0.
|
|
19
|
-
mmar_mapi-1.0.
|
|
16
|
+
mmar_mapi-1.0.6.dist-info/licenses/LICENSE,sha256=2A90w8WjhOgQXnFuUijKJYazaqZ4_NTokYb9Po4y-9k,1061
|
|
17
|
+
mmar_mapi-1.0.6.dist-info/WHEEL,sha256=Jb20R3Ili4n9P1fcwuLup21eQ5r9WXhs4_qy7VTrgPI,79
|
|
18
|
+
mmar_mapi-1.0.6.dist-info/METADATA,sha256=dxEk5xdH21b8jW053i5ojhUkguzCkgJoZMRc_JIRyAo,914
|
|
19
|
+
mmar_mapi-1.0.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|