MainShortcuts2 2.8.4__tar.gz → 2.8.5__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.5}/PKG-INFO +1 -1
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/pyproject.toml +1 -1
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/_module_info.py +1 -1
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/advanced.py +31 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/aiohttp_ex/web/__init__.py +9 -5
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/str.py +14 -15
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/utils.py +68 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/README.md +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/__init__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/__main__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/_any2json_regs.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/_ms2app_regs.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/_ms2dat_auto.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/any2json.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/api/base.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/api/gigachat.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/api/github.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/api/russian_trusted_root_ca_pem.crt +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/api/russian_trusted_sub_ca_pem.crt +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/api/webdav.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/cfg.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/core.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/core_config.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/dict.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/dir.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/__init__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/aiohttp_ex/web/__main__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/datetime_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/pathlib_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/pil_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/psutil_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/sqlite_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ex/urlparse_ex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/file.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/gui_scripts/__init__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/gui_scripts/ms2_hash_gen.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/gui_scripts/utils.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/java_ext/__init__.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/java_ext/ms2ext.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/json.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/linux.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/list.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ms2app.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ms2dat1.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/ms2hash.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/path.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/proc.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/regex.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/special_chars.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/sql/_sql_base.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/sql/mysql.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/sql/postgresql.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/sql/sqlite.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/term.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/types.py +0 -0
- {mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/src/MainShortcuts2/win.py +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
name = 'mainshortcuts2'
|
|
2
|
-
version = '2.8.
|
|
2
|
+
version = '2.8.5'
|
|
@@ -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.5}/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()
|
|
@@ -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.5}/src/MainShortcuts2/api/russian_trusted_root_ca_pem.crt
RENAMED
|
File without changes
|
{mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/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.5}/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
|
|
File without changes
|
{mainshortcuts2-2.8.4 → mainshortcuts2-2.8.5}/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
|
|
File without changes
|
|
File without changes
|