MainShortcuts2 2.8.4__tar.gz → 2.8.6__tar.gz
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.
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/PKG-INFO +1 -1
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/pyproject.toml +1 -1
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/_module_info.py +1 -1
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/advanced.py +31 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/aiohttp_ex/web/__init__.py +9 -5
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/pathlib_ex.py +96 -2
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/java_ext/__init__.py +58 -20
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/path.py +9 -32
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/str.py +14 -15
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/utils.py +68 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/README.md +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/__init__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/__main__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/_any2json_regs.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/_ms2app_regs.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/_ms2dat_auto.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/any2json.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/api/base.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/api/gigachat.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/api/github.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/api/russian_trusted_root_ca_pem.crt +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/api/russian_trusted_sub_ca_pem.crt +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/api/webdav.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/cfg.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/core.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/core_config.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/dict.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/dir.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/__init__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/aiohttp_ex/web/__main__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/datetime_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/pil_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/psutil_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/sqlite_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/urlparse_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/file.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/gui_scripts/__init__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/gui_scripts/ms2_hash_gen.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/gui_scripts/utils.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/java_ext/ms2ext.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/json.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/linux.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/list.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ms2app.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ms2dat1.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ms2hash.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/proc.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/regex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/special_chars.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/sql/_sql_base.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/sql/mysql.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/sql/postgresql.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/sql/sqlite.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/term.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/types.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/win.py +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
name = 'mainshortcuts2'
|
|
2
|
-
version = '2.8.
|
|
2
|
+
version = '2.8.6'
|
|
@@ -1110,3 +1110,34 @@ class NetBroadcastReceiver(_ServerBase):
|
|
|
1110
1110
|
break
|
|
1111
1111
|
self.recv()
|
|
1112
1112
|
self._stopping = False
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
class SimpleBcrypt:
|
|
1116
|
+
"""Упрощение методов `bcrypt`. Библиотека `bcrypt` должна быть доступна
|
|
1117
|
+
```
|
|
1118
|
+
pip install -U bcrypt
|
|
1119
|
+
```"""
|
|
1120
|
+
|
|
1121
|
+
def __init__(self):
|
|
1122
|
+
import bcrypt
|
|
1123
|
+
self._b = bcrypt
|
|
1124
|
+
self.encoding = "utf-8"
|
|
1125
|
+
self.salt_prefix = b"2b"
|
|
1126
|
+
self.salt_rounds = 12
|
|
1127
|
+
|
|
1128
|
+
def _to_bytes(self, s: bytes | str) -> bytes:
|
|
1129
|
+
if isinstance(s, str):
|
|
1130
|
+
return s.encode(self.encoding)
|
|
1131
|
+
return s
|
|
1132
|
+
|
|
1133
|
+
def gen_salt(self):
|
|
1134
|
+
"""Сгенерировать соль для хеширования"""
|
|
1135
|
+
return self._b.gensalt(self.salt_rounds, self.salt_prefix)
|
|
1136
|
+
|
|
1137
|
+
def hash_pwd(self, pwd: bytes | str):
|
|
1138
|
+
"""Хешировать пароль"""
|
|
1139
|
+
return self._b.hashpw(self._to_bytes(pwd), self.gen_salt())
|
|
1140
|
+
|
|
1141
|
+
def check_pwd(self, pwd: bytes | str, hashed_pwd: bytes | str):
|
|
1142
|
+
"""Проверить пароль"""
|
|
1143
|
+
return self._b.checkpw(self._to_bytes(pwd), self._to_bytes(hashed_pwd))
|
{mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/aiohttp_ex/web/__init__.py
RENAMED
|
@@ -24,11 +24,11 @@ def wrap_handler(app: "Application", handler: Handler):
|
|
|
24
24
|
if isinstance(resp, int): # Код статуса
|
|
25
25
|
resp = Response(status=resp)
|
|
26
26
|
elif isinstance(resp, ApiResult): # Результат API обработчика
|
|
27
|
-
resp = resp.make_resp(req.
|
|
27
|
+
resp = resp.make_resp(req.headers.get("Accept"))
|
|
28
28
|
elif isinstance(resp, PATH_TYPES): # Локальный файл
|
|
29
29
|
resp = FileResponse(resp)
|
|
30
30
|
except ApiResult as exc: # Результат API исключения
|
|
31
|
-
resp = exc.make_resp(req.
|
|
31
|
+
resp = exc.make_resp(req.headers.get("Accept"))
|
|
32
32
|
except Exception as exc:
|
|
33
33
|
app.logger.exception("Failed to process request", exc_info=exc)
|
|
34
34
|
resp = Response(status=500, reason="Internal server error")
|
|
@@ -167,12 +167,16 @@ class ApiResult(BaseException):
|
|
|
167
167
|
from MainShortcuts2 import ms2dat1
|
|
168
168
|
return "application/x-ms2dat1", ms2dat1.dumps(self.to_dict())
|
|
169
169
|
|
|
170
|
-
def make_resp(self,
|
|
170
|
+
def make_resp(self, accept_header: str = None):
|
|
171
171
|
"""Создать ответ в указаном формате, по умолчанию JSON"""
|
|
172
|
+
use_ms2dat, use_yaml = False, False
|
|
173
|
+
if accept_header:
|
|
174
|
+
use_ms2dat = "application/x-ms2dat1" in accept_header
|
|
175
|
+
use_yaml = ("application/yaml" in accept_header) and ("application/json" not in accept_header)
|
|
172
176
|
try:
|
|
173
|
-
if
|
|
177
|
+
if use_ms2dat:
|
|
174
178
|
ctype, body = self._to_ms2dat1()
|
|
175
|
-
elif
|
|
179
|
+
elif use_yaml:
|
|
176
180
|
ctype, body = self._to_yaml()
|
|
177
181
|
else: # Если запрошенный формат не поддерживается
|
|
178
182
|
ctype, body = self._to_json()
|
|
@@ -2,13 +2,23 @@ import os
|
|
|
2
2
|
import pathlib
|
|
3
3
|
import shutil
|
|
4
4
|
import typing
|
|
5
|
+
import enum
|
|
6
|
+
from functools import cached_property
|
|
5
7
|
from MainShortcuts2 import ms
|
|
6
8
|
from os import fspath
|
|
7
9
|
from stat import S_ISDIR, S_ISREG
|
|
8
10
|
|
|
9
11
|
|
|
12
|
+
class ms2hash_version(enum.IntEnum):
|
|
13
|
+
LEGACY = enum.auto()
|
|
14
|
+
V0 = enum.auto()
|
|
15
|
+
VA = enum.auto()
|
|
16
|
+
VB = enum.auto()
|
|
17
|
+
VH = enum.auto()
|
|
18
|
+
|
|
19
|
+
|
|
10
20
|
class Path(pathlib.Path):
|
|
11
|
-
@
|
|
21
|
+
@cached_property
|
|
12
22
|
def ms_path(self):
|
|
13
23
|
"""Объект `ms.path.Path`"""
|
|
14
24
|
return ms.path.Path(self)
|
|
@@ -171,4 +181,88 @@ class Path(pathlib.Path):
|
|
|
171
181
|
|
|
172
182
|
def read_ms2dat(self, **kw):
|
|
173
183
|
"""Прочитать данные в формате MS2Dat"""
|
|
174
|
-
ms.ms2dat.read_file(self, **kw)
|
|
184
|
+
return ms.ms2dat.read_file(self, **kw)
|
|
185
|
+
|
|
186
|
+
def copy_to_io(self, fdest: typing.BinaryIO):
|
|
187
|
+
"""Скопировать содержимое в открытый файл"""
|
|
188
|
+
with self.open("rb") as fsrc:
|
|
189
|
+
shutil.copyfileobj(fsrc, fdest)
|
|
190
|
+
|
|
191
|
+
def _compress(self, opn: typing.Callable[[typing.Self], typing.BinaryIO], suffix: str, dest: os.PathLike = None, keep=False, **kw):
|
|
192
|
+
if dest is None:
|
|
193
|
+
dest = self.with_name(self.name + suffix)
|
|
194
|
+
else:
|
|
195
|
+
dest = type(self)(dest)
|
|
196
|
+
with opn(dest, **kw) as f:
|
|
197
|
+
self.copy_to_io(f)
|
|
198
|
+
if not keep:
|
|
199
|
+
self.unlink()
|
|
200
|
+
return dest
|
|
201
|
+
|
|
202
|
+
def compress_bz2(self, dest=None, keep=False, **kw):
|
|
203
|
+
"""Сжать через bzip2"""
|
|
204
|
+
import bz2
|
|
205
|
+
return self._compress(bz2.open, ".bz2", dest, keep, mode="wb", **kw)
|
|
206
|
+
|
|
207
|
+
def compress_gzip(self, dest=None, keep=False, **kw):
|
|
208
|
+
"""Сжать через gzip"""
|
|
209
|
+
import gzip
|
|
210
|
+
return self._compress(gzip.open, ".gz", dest, keep, mode="wb", **kw)
|
|
211
|
+
|
|
212
|
+
def compress_lzma(self, / dest=None, keep=False, **kw):
|
|
213
|
+
"""Сжать через lzma"""
|
|
214
|
+
import lzma
|
|
215
|
+
return self._compress(lzma.open, ".lzma", dest, keep, mode="wb", **kw)
|
|
216
|
+
|
|
217
|
+
def compress_zstd(self, dest=None, keep=False, **kw):
|
|
218
|
+
"""Сжать через zstandard"""
|
|
219
|
+
import zstandard
|
|
220
|
+
return self._compress(zstandard.open, ".zst", dest, keep, mode="wb", **kw)
|
|
221
|
+
|
|
222
|
+
def hash(self, alg: str, bufsize=2**18):
|
|
223
|
+
"""Хешировать файл одним алгоритмом"""
|
|
224
|
+
import hashlib
|
|
225
|
+
with self.open("rb") as f:
|
|
226
|
+
return hashlib.file_digest(f, alg, _bufsize=bufsize).digest()
|
|
227
|
+
|
|
228
|
+
def hash_multi(self, algs: set[str], bufsize=2**18) -> dict[str, bytes]:
|
|
229
|
+
"""Хешировать файл несколькими алгоритмами"""
|
|
230
|
+
if not algs:
|
|
231
|
+
return {}
|
|
232
|
+
import hashlib
|
|
233
|
+
hashes = {i: hashlib.new(i) for i in algs}
|
|
234
|
+
updaters = [i.update for i in hashes.values()]
|
|
235
|
+
with self.open("rb") as f:
|
|
236
|
+
read = f.read
|
|
237
|
+
while True:
|
|
238
|
+
buf = read(bufsize)
|
|
239
|
+
if not buf:
|
|
240
|
+
break
|
|
241
|
+
for upd in updaters:
|
|
242
|
+
upd(buf)
|
|
243
|
+
return {k: v.digest() for k, v in hashes.items()}
|
|
244
|
+
|
|
245
|
+
def generate_ms2hash(self, alg="sha3-256", overwrite=False, version=ms2hash_version.LEGACY, **kw):
|
|
246
|
+
"""Сгенерировать файл хеша рядом с этим файлом. **Внимание**: версия по умолчанию изменится в будущем обновлении"""
|
|
247
|
+
if version == ms2hash_version.LEGACY:
|
|
248
|
+
dest = self.with_name(self.name + ms.ms2hash.HASH_SUFFIX)
|
|
249
|
+
if dest.exists() and not overwrite:
|
|
250
|
+
raise FileExistsError(dest)
|
|
251
|
+
hash = ms.ms2hash.Format1.generate(self, **kw)
|
|
252
|
+
return dest.write_json(hash.to_dict())
|
|
253
|
+
from MPL import ms2hash # WIP, скоро будет в MS2
|
|
254
|
+
if version == ms2hash_version.V0:
|
|
255
|
+
v = ms2hash.VERSION_0
|
|
256
|
+
elif version == ms2hash_version.VA:
|
|
257
|
+
v = ms2hash.VERSION_A
|
|
258
|
+
elif version == ms2hash_version.VB:
|
|
259
|
+
v = ms2hash.VERSION_B
|
|
260
|
+
elif version == ms2hash_version.VH:
|
|
261
|
+
v = ms2hash.VERSION_H
|
|
262
|
+
else:
|
|
263
|
+
raise ValueError("Invalid hash version: %s" % version)
|
|
264
|
+
dest = self.with_name(self.name + ms2hash.FILE_SUFFIX)
|
|
265
|
+
if dest.exists() and not overwrite:
|
|
266
|
+
raise FileExistsError(dest)
|
|
267
|
+
hash = ms2hash.HashInfo.from_file(alg, self, **kw)
|
|
268
|
+
return dest.write_bytes(hash.to_auto(v))
|
|
@@ -39,7 +39,10 @@ def _parse_java_version(text: str):
|
|
|
39
39
|
return list(map(int, text.split("_", 1)[0].split(".")))
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
_java_version_cache: dict[str, list[int]] = {}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _detect_java_version(file: Path):
|
|
43
46
|
release_file = file.parent.parent / "release"
|
|
44
47
|
if release_file.exists():
|
|
45
48
|
try:
|
|
@@ -58,13 +61,21 @@ def detect_java_version(file: Path):
|
|
|
58
61
|
raise RuntimeError("Couldn't determine the Java version") from None
|
|
59
62
|
|
|
60
63
|
|
|
64
|
+
def detect_java_version(file: Path):
|
|
65
|
+
file = file.resolve()
|
|
66
|
+
version = _java_version_cache.get(os.fspath(file))
|
|
67
|
+
if not version:
|
|
68
|
+
version = _java_version_cache[os.fspath(file)] = _detect_java_version(file)
|
|
69
|
+
return version
|
|
70
|
+
|
|
71
|
+
|
|
61
72
|
class IncompatibleJava(Exception):
|
|
62
73
|
pass
|
|
63
74
|
|
|
64
75
|
|
|
65
76
|
class InfoDict(dict):
|
|
66
77
|
@property
|
|
67
|
-
def builded_at(self):
|
|
78
|
+
def builded_at(self) -> int:
|
|
68
79
|
"""Дата сборки релиза (Unix timestamp)"""
|
|
69
80
|
return self["builded_at"]
|
|
70
81
|
|
|
@@ -89,17 +100,17 @@ class InfoDict(dict):
|
|
|
89
100
|
return self.get("max_java_version")
|
|
90
101
|
|
|
91
102
|
@property
|
|
92
|
-
def name(self):
|
|
103
|
+
def name(self) -> str:
|
|
93
104
|
"""Название"""
|
|
94
105
|
return self["name"]
|
|
95
106
|
|
|
96
107
|
@property
|
|
97
|
-
def version(self):
|
|
108
|
+
def version(self) -> str:
|
|
98
109
|
"""Название версии"""
|
|
99
110
|
return self["version"]
|
|
100
111
|
|
|
101
112
|
@property
|
|
102
|
-
def version_id(self):
|
|
113
|
+
def version_id(self) -> int:
|
|
103
114
|
"""ID версии"""
|
|
104
115
|
return self["version_id"]
|
|
105
116
|
|
|
@@ -121,6 +132,11 @@ class InfoDict(dict):
|
|
|
121
132
|
"""Проверить находится ли ID версии в диапазоне"""
|
|
122
133
|
return bool(min_id <= self.version_id < max_id)
|
|
123
134
|
|
|
135
|
+
@property
|
|
136
|
+
def dependencies(self) -> list[tuple[str, str, str]]:
|
|
137
|
+
"""Зависимости"""
|
|
138
|
+
return self.get("dependencies") or []
|
|
139
|
+
|
|
124
140
|
|
|
125
141
|
class JavaExtManager(ms.ObjectBase):
|
|
126
142
|
"""Менеджер версий JAR файла с кешированием"""
|
|
@@ -131,8 +147,7 @@ class JavaExtManager(ms.ObjectBase):
|
|
|
131
147
|
self.version_cache: "dict[str,JavaExtVersion]" = {}
|
|
132
148
|
|
|
133
149
|
@cached_property
|
|
134
|
-
def
|
|
135
|
-
"""Папка кеша"""
|
|
150
|
+
def root_dir(self):
|
|
136
151
|
plat = ms.advanced.get_platform()
|
|
137
152
|
if plat.is_mustdie:
|
|
138
153
|
if os.environ.get("LOCALAPPDATA"):
|
|
@@ -144,7 +159,16 @@ class JavaExtManager(ms.ObjectBase):
|
|
|
144
159
|
base = Path(os.environ["XDG_DATA_HOME"])
|
|
145
160
|
else:
|
|
146
161
|
base = Path.home() / ".local/share"
|
|
147
|
-
|
|
162
|
+
return base / "MainPlay_TG/MainShortcuts2/java_ext_cache_v1"
|
|
163
|
+
|
|
164
|
+
@cached_property
|
|
165
|
+
def lib_dir(self):
|
|
166
|
+
return self.root_dir / "lib"
|
|
167
|
+
|
|
168
|
+
@cached_property
|
|
169
|
+
def dir(self):
|
|
170
|
+
"""Папка кеша"""
|
|
171
|
+
result = self.root_dir / self.repo[0] / self.repo[1]
|
|
148
172
|
return result.resolve().any_mkdir()
|
|
149
173
|
|
|
150
174
|
def get_version(self, version_name: str):
|
|
@@ -155,6 +179,14 @@ class JavaExtManager(ms.ObjectBase):
|
|
|
155
179
|
self.version_cache[version_name] = version
|
|
156
180
|
return self.version_cache[version_name]
|
|
157
181
|
|
|
182
|
+
def get_lib(self, group_id: str, artifact_id: str, version: str):
|
|
183
|
+
filename = f"{group_id.replace(".", "/")}/{artifact_id}/{version}/{artifact_id}-{version}.jar"
|
|
184
|
+
file = self.lib_dir / filename
|
|
185
|
+
if not file.exists():
|
|
186
|
+
file.parent.any_mkdir()
|
|
187
|
+
ms.utils.download_file(f"https://repo1.maven.org/maven2/{filename}", file, session=self.gh.http)
|
|
188
|
+
return file
|
|
189
|
+
|
|
158
190
|
def iter_online_releases(self, count=github.MAX_PER_PAGE):
|
|
159
191
|
"""Итерация релизов с GitHub"""
|
|
160
192
|
return self.gh.releases.list_iter(*self.repo, count)
|
|
@@ -307,33 +339,39 @@ class JavaExtVersion(ms.ObjectBase):
|
|
|
307
339
|
if not keep_info:
|
|
308
340
|
self.info_path.remove()
|
|
309
341
|
|
|
310
|
-
def _popen(self, args, **kw):
|
|
342
|
+
def _popen(self, args, classpath: list[Path] = None, **kw):
|
|
311
343
|
if not self._java_checked:
|
|
312
344
|
self.info.check_java_file(self.java_bin)
|
|
313
345
|
self._java_checked = True
|
|
314
|
-
|
|
346
|
+
cp = os.path.pathsep.join(map(os.fspath, [*self.dependencies_files, *(classpath or [])]))
|
|
347
|
+
return subprocess.Popen([str(self.java_bin), "-cp", cp, *args], **kw)
|
|
315
348
|
|
|
316
|
-
def _run(self, args, **kw) -> subprocess.CompletedProcess:
|
|
349
|
+
def _run(self, args, classpath: list[Path] = None, **kw) -> subprocess.CompletedProcess:
|
|
317
350
|
kw.setdefault("check", True)
|
|
318
351
|
if not self._java_checked:
|
|
319
352
|
self.info.check_java_file(self.java_bin)
|
|
320
353
|
self._java_checked = True
|
|
321
|
-
|
|
354
|
+
cp = os.path.pathsep.join(map(os.fspath, [*self.dependencies_files, *(classpath or [])]))
|
|
355
|
+
return subprocess.run([str(self.java_bin), "-cp", cp, *args], **kw)
|
|
322
356
|
|
|
323
|
-
def popen_class_raw(self,
|
|
324
|
-
return self._popen([
|
|
357
|
+
def popen_class_raw(self, class_name: str, args: list[str] = [], **kw):
|
|
358
|
+
return self._popen([class_name, *args], [self.jar_path], **kw)
|
|
325
359
|
|
|
326
|
-
def popen_class(self,
|
|
327
|
-
return self.popen_class_raw(self.info.classes[
|
|
360
|
+
def popen_class(self, class_alias: str, args: list[str] = [], **kw):
|
|
361
|
+
return self.popen_class_raw(self.info.classes[class_alias], args, **kw)
|
|
328
362
|
|
|
329
363
|
def popen(self, args: list[str], **kw):
|
|
330
364
|
return self._popen(["-jar", str(self.jar_path), *args], **kw)
|
|
331
365
|
|
|
332
|
-
def run_class_raw(self,
|
|
333
|
-
return self._run([
|
|
366
|
+
def run_class_raw(self, class_name: str, args: list[str] = [], **kw):
|
|
367
|
+
return self._run([class_name, *args], [self.jar_path], **kw)
|
|
334
368
|
|
|
335
|
-
def run_class(self,
|
|
336
|
-
return self.run_class_raw(self.info.classes[
|
|
369
|
+
def run_class(self, class_alias: str, args: list[str] = [], **kw):
|
|
370
|
+
return self.run_class_raw(self.info.classes[class_alias], args, **kw)
|
|
337
371
|
|
|
338
372
|
def run(self, args: list[str], **kw):
|
|
339
373
|
return self._run(["-jar", str(self.jar_path), *args], **kw)
|
|
374
|
+
|
|
375
|
+
@cached_property
|
|
376
|
+
def dependencies_files(self):
|
|
377
|
+
return [self.mgr.get_lib(*i) for i in self.info.dependencies]
|
|
@@ -337,47 +337,24 @@ class Path(os.PathLike):
|
|
|
337
337
|
"""Открыть файл на чтение/запись"""
|
|
338
338
|
return open(self.path, mode, **kw)
|
|
339
339
|
|
|
340
|
-
def hash(self, algorithm: str, chunk_size=ms.file.CHUNK_SIZE)
|
|
340
|
+
def hash(self, algorithm: str, chunk_size=ms.file.CHUNK_SIZE):
|
|
341
341
|
"""Хеш файла (`bytes`)"""
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
rf = f.read # read func
|
|
346
|
-
uf = hash.update # update func
|
|
347
|
-
while True:
|
|
348
|
-
b = rf(chunk_size)
|
|
349
|
-
if not b:
|
|
350
|
-
break
|
|
351
|
-
uf(b)
|
|
352
|
-
return hash.digest()
|
|
353
|
-
|
|
354
|
-
def hash_hex(self, algorithm: str, **kw) -> str:
|
|
342
|
+
return self.pathlib_path.hash(algorithm, bufsize=chunk_size)
|
|
343
|
+
|
|
344
|
+
def hash_hex(self, algorithm: str, **kw):
|
|
355
345
|
"""Хеш файла (`bytes.hex()`)"""
|
|
356
346
|
return self.hash(algorithm, **kw).hex()
|
|
357
347
|
|
|
358
|
-
def hash_b85(self, algorithm: str, **kw)
|
|
348
|
+
def hash_b85(self, algorithm: str, **kw):
|
|
359
349
|
"""Хеш файла (`base85`)"""
|
|
360
350
|
from base64 import b85encode
|
|
361
351
|
return b85encode(self.hash(algorithm, **kw)).decode()
|
|
362
352
|
|
|
363
|
-
def multi_hash(self, algorithms: list[str], chunk_size=ms.file.CHUNK_SIZE)
|
|
353
|
+
def multi_hash(self, algorithms: list[str], chunk_size=ms.file.CHUNK_SIZE):
|
|
364
354
|
"""Хеш файла (`bytes`) для нескольких алгоритмов"""
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
hashes = {i: hashlib.new(i) for i in set(algorithms)}
|
|
369
|
-
ufs = [i.update for i in hashes.values()]
|
|
370
|
-
with self.open_file("rb") as f:
|
|
371
|
-
rf = f.read # read func
|
|
372
|
-
while True:
|
|
373
|
-
b = rf(chunk_size)
|
|
374
|
-
if not b:
|
|
375
|
-
break
|
|
376
|
-
for uf in ufs:
|
|
377
|
-
uf(b)
|
|
378
|
-
return {k: v.digest() for k, v in hashes.items()}
|
|
379
|
-
|
|
380
|
-
def multi_hash_hex(self, algorithms: list[str], **kw) -> dict[str, str]:
|
|
355
|
+
return self.pathlib_path.hash_multi(algorithms, bufsize=chunk_size)
|
|
356
|
+
|
|
357
|
+
def multi_hash_hex(self, algorithms: list[str], **kw):
|
|
381
358
|
"""Хеш файла в HEX строке для нескольких алгоритмов"""
|
|
382
359
|
return {k: v.hex() for k, v in self.multi_hash(algorithms, **kw).items()}
|
|
383
360
|
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"""Работа со строками"""
|
|
2
|
-
|
|
3
|
-
from typing import *
|
|
2
|
+
import typing
|
|
4
3
|
|
|
5
4
|
|
|
6
|
-
def list2str(a:
|
|
5
|
+
def list2str(a: typing.Iterable[str]):
|
|
7
6
|
"""Преобразовать каждый элемент списка в строку"""
|
|
8
|
-
|
|
9
|
-
for i in a:
|
|
10
|
-
b.append(str(i))
|
|
11
|
-
return b
|
|
7
|
+
return [str(i) for i in a]
|
|
12
8
|
|
|
13
9
|
|
|
14
10
|
def dict2str(a: dict) -> dict:
|
|
@@ -19,13 +15,10 @@ def dict2str(a: dict) -> dict:
|
|
|
19
15
|
return b
|
|
20
16
|
|
|
21
17
|
|
|
22
|
-
class
|
|
18
|
+
class replace:
|
|
23
19
|
"""Функции для замены текста"""
|
|
24
|
-
|
|
25
|
-
def
|
|
26
|
-
pass
|
|
27
|
-
|
|
28
|
-
def multi(self, text: str, d: dict = None, **kw) -> str:
|
|
20
|
+
@classmethod
|
|
21
|
+
def multi(cls, text: str, d: dict = None, **kw) -> str:
|
|
29
22
|
"""Мульти-замена {"что заменить":"чем заменить"}"""
|
|
30
23
|
if not d is None:
|
|
31
24
|
kw.update(d)
|
|
@@ -34,7 +27,8 @@ class _Replace:
|
|
|
34
27
|
t = t.replace(k, str(v))
|
|
35
28
|
return t
|
|
36
29
|
|
|
37
|
-
|
|
30
|
+
@classmethod
|
|
31
|
+
def all(cls, text: str, fr: str, to: str) -> str:
|
|
38
32
|
"""Замена пока заменяемый текст не исчезнет"""
|
|
39
33
|
t = str(text)
|
|
40
34
|
a = str(fr)
|
|
@@ -46,4 +40,9 @@ class _Replace:
|
|
|
46
40
|
return t
|
|
47
41
|
|
|
48
42
|
|
|
49
|
-
|
|
43
|
+
def join_list(lst: typing.Iterable[str], midsep=", ", lastsep=" и "):
|
|
44
|
+
"""Объединить список в строку с отличающимся последним разделителем"""
|
|
45
|
+
lst = [str(i) for i in lst]
|
|
46
|
+
if len(lst) < 3:
|
|
47
|
+
return lastsep.join(lst)
|
|
48
|
+
return midsep.join(lst[:-1]) + lastsep + lst[-1]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Различные утилиты, иногда требующие сторонних модулей"""
|
|
2
2
|
import atexit
|
|
3
|
+
import base64
|
|
3
4
|
import builtins
|
|
4
5
|
import importlib
|
|
5
6
|
import logging
|
|
@@ -7,6 +8,7 @@ import os
|
|
|
7
8
|
import sys
|
|
8
9
|
import time
|
|
9
10
|
import typing
|
|
11
|
+
import uuid as UuidModule
|
|
10
12
|
from .core import ms
|
|
11
13
|
from contextlib import ExitStack
|
|
12
14
|
from functools import wraps
|
|
@@ -1208,3 +1210,69 @@ class FilterGetAttr(Filter):
|
|
|
1208
1210
|
class FilterGetItem(FilterGetAttr):
|
|
1209
1211
|
def __call__(self, obj):
|
|
1210
1212
|
return obj[self.name]
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
gen_uuid = UuidModule.uuid4
|
|
1216
|
+
if not typing.TYPE_CHECKING:
|
|
1217
|
+
# Выбрать быстрейшую функцию
|
|
1218
|
+
for i in (8, 7, 6):
|
|
1219
|
+
j = f"uuid{i}"
|
|
1220
|
+
if hasattr(UuidModule, j):
|
|
1221
|
+
gen_uuid = getattr(UuidModule, j)
|
|
1222
|
+
break
|
|
1223
|
+
del i, j
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
def short_b64encode(s: bytes, **kw):
|
|
1227
|
+
"""Кодирование в Base64 с удалением заполнителей"""
|
|
1228
|
+
return base64.b64encode(s, **kw).rstrip(b"=")
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
def short_b64decode(s: bytes, **kw):
|
|
1232
|
+
"""Декодирование Base64 с восстановлением заполнителей"""
|
|
1233
|
+
n = -len(s) % 4
|
|
1234
|
+
if n:
|
|
1235
|
+
suffix = ("=" if isinstance(s, str) else b"=") * n
|
|
1236
|
+
return base64.b64decode(s + suffix, **kw)
|
|
1237
|
+
return base64.b64decode(s, **kw)
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
def short_urlsafe_b64encode(s: bytes):
|
|
1241
|
+
"""Аналогично `short_b64encode`, но безопасен для URL"""
|
|
1242
|
+
return base64.urlsafe_b64encode(s).rstrip(b"=")
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
def short_urlsafe_b64decode(s: bytes):
|
|
1246
|
+
"""Аналогично `short_b64decode`, но безопасен для URL"""
|
|
1247
|
+
n = -len(s) % 4
|
|
1248
|
+
if n:
|
|
1249
|
+
suffix = ("=" if isinstance(s, str) else b"=") * n
|
|
1250
|
+
return base64.urlsafe_b64decode(s + suffix)
|
|
1251
|
+
return base64.urlsafe_b64decode(s)
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
def uuid2bytes(uuid):
|
|
1255
|
+
"""Конвертировать UUID в байты"""
|
|
1256
|
+
if isinstance(uuid, bytes):
|
|
1257
|
+
return uuid
|
|
1258
|
+
return uuid2obj(uuid).bytes
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
def uuid2obj(uuid):
|
|
1262
|
+
"""Конвертировать UUID в объект"""
|
|
1263
|
+
if isinstance(uuid, UuidModule.UUID):
|
|
1264
|
+
return uuid
|
|
1265
|
+
if isinstance(uuid, bytes):
|
|
1266
|
+
return UuidModule.UUID(bytes=uuid)
|
|
1267
|
+
if isinstance(uuid, memoryview):
|
|
1268
|
+
return UuidModule.UUID(bytes=uuid.tobytes())
|
|
1269
|
+
if isinstance(uuid, str):
|
|
1270
|
+
return UuidModule.UUID(hex=uuid)
|
|
1271
|
+
raise TypeError("Invalid uuid type")
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
def uuid2str(uuid):
|
|
1275
|
+
"""Конвертировать UUID в строку"""
|
|
1276
|
+
if isinstance(uuid, str):
|
|
1277
|
+
return uuid
|
|
1278
|
+
return str(uuid2obj(uuid))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/api/russian_trusted_root_ca_pem.crt
RENAMED
|
File without changes
|
{mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/api/russian_trusted_sub_ca_pem.crt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/ex/aiohttp_ex/web/__main__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mainshortcuts2-2.8.4 → mainshortcuts2-2.8.6}/src/MainShortcuts2/gui_scripts/ms2_hash_gen.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|