MainShortcuts2 2.9.0__tar.gz → 2.9.2__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.
Files changed (57) hide show
  1. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/PKG-INFO +1 -1
  2. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/pyproject.toml +1 -1
  3. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/_module_info.py +1 -1
  4. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/api/base.py +19 -20
  5. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/sqlite_ex.py +5 -3
  6. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/sql/mysql.py +1 -1
  7. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/sql/postgresql.py +1 -1
  8. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/sql/sqlite.py +1 -1
  9. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/README.md +0 -0
  10. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/__init__.py +0 -0
  11. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/__main__.py +0 -0
  12. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/_any2json_regs.py +0 -0
  13. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/_ms2app_regs.py +0 -0
  14. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/_ms2dat_auto.py +0 -0
  15. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/advanced.py +0 -0
  16. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/any2json.py +0 -0
  17. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/api/gigachat.py +0 -0
  18. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/api/github.py +0 -0
  19. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/api/russian_trusted_root_ca_pem.crt +0 -0
  20. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/api/russian_trusted_sub_ca_pem.crt +0 -0
  21. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/api/webdav.py +0 -0
  22. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/cfg.py +0 -0
  23. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/core.py +0 -0
  24. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/core_config.py +0 -0
  25. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/dict.py +0 -0
  26. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/dir.py +0 -0
  27. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/__init__.py +0 -0
  28. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/aiohttp_ex/web/__init__.py +0 -0
  29. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/aiohttp_ex/web/__main__.py +0 -0
  30. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/datetime_ex.py +0 -0
  31. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/pathlib_ex.py +0 -0
  32. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/pil_ex.py +0 -0
  33. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/psutil_ex.py +0 -0
  34. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ex/urlparse_ex.py +0 -0
  35. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/file.py +0 -0
  36. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/gui_scripts/__init__.py +0 -0
  37. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/gui_scripts/ms2_hash_gen.py +0 -0
  38. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/gui_scripts/utils.py +0 -0
  39. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/java_ext/__init__.py +0 -0
  40. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/java_ext/ms2ext.py +0 -0
  41. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/json.py +0 -0
  42. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/linux.py +0 -0
  43. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/list.py +0 -0
  44. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ms2app.py +0 -0
  45. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ms2dat1.py +0 -0
  46. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ms2dat1crypto.py +0 -0
  47. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/ms2hash.py +0 -0
  48. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/path.py +0 -0
  49. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/proc.py +0 -0
  50. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/regex.py +0 -0
  51. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/special_chars.py +0 -0
  52. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/sql/_sql_base.py +0 -0
  53. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/str.py +0 -0
  54. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/term.py +0 -0
  55. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/types.py +0 -0
  56. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/utils.py +0 -0
  57. {mainshortcuts2-2.9.0 → mainshortcuts2-2.9.2}/src/MainShortcuts2/win.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MainShortcuts2
3
- Version: 2.9.0
3
+ Version: 2.9.2
4
4
  Summary: Сокращение и улучшение функций + консольные утилиты
5
5
  Author: MainPlay TG
6
6
  Author-email: xbox.roman6666666666@gmail.com
@@ -1,5 +1,5 @@
1
1
  [tool.poetry]
2
- version = "2.9.0"
2
+ version = "2.9.2"
3
3
  name = "MainShortcuts2"
4
4
  description = "Сокращение и улучшение функций + консольные утилиты"
5
5
  authors = ["MainPlay TG <xbox.roman6666666666@gmail.com>"]
@@ -1,2 +1,2 @@
1
1
  name = 'mainshortcuts2'
2
- version = '2.9.0'
2
+ version = '2.9.2'
@@ -1,5 +1,6 @@
1
1
  import requests
2
2
  import requests.auth
3
+ from functools import cached_property
3
4
  from MainShortcuts2 import ms
4
5
  USER_AGENTS: dict[str, str] = {}
5
6
  USER_AGENTS["Android"] = "Mozilla/5.0 (Linux; Android 13; K) Chrome/128.0.6613.146"
@@ -26,7 +27,6 @@ def setdefattr(obj, attr, value):
26
27
  class BaseClient(ms.ObjectBase):
27
28
  """Базовый клиент для HTTP API"""
28
29
  _enable_cookies: bool
29
- _http: requests.Session
30
30
  _url_data: dict[str, str]
31
31
  _url: str
32
32
  cache: "CacheStorage"
@@ -35,11 +35,12 @@ class BaseClient(ms.ObjectBase):
35
35
  self._init(**kw)
36
36
 
37
37
  def _init(self, session: requests.Session = None):
38
- setdefattr(self, "_http", session)
39
38
  setdefattr(self, "_enable_cookies", False)
40
39
  setdefattr(self, "_url_data", {})
41
40
  setdefattr(self, "_url", "https://example.com/api/{method}")
42
41
  setdefattr(self, "cache", CacheStorage())
42
+ if session:
43
+ self.__dict__["http"] = session
43
44
 
44
45
  def __enter__(self):
45
46
  return self
@@ -64,12 +65,10 @@ class BaseClient(ms.ObjectBase):
64
65
  def _params(self):
65
66
  return self.http.params
66
67
 
67
- @property
68
- def http(self) -> requests.Session:
68
+ @cached_property
69
+ def http(self):
69
70
  """HTTP сессия"""
70
- if self._http is None:
71
- self._http = requests.Session()
72
- return self._http
71
+ return requests.Session()
73
72
 
74
73
  def _request(self, http_method: str, api_method: str, *, raise_for_status: bool = True, url_data: dict[str, str] = None, **kw):
75
74
  _url_data = self._url_data.copy()
@@ -83,26 +82,18 @@ class BaseClient(ms.ObjectBase):
83
82
  result.raise_for_status()
84
83
  return result
85
84
 
86
- def request(self, httpm, apim, **kw) -> requests.Response:
85
+ def request(self, httpm: str, apim: str, **kw):
87
86
  """Отправить запрос к API"""
88
87
  return self._request(httpm, apim, **kw)
89
88
 
90
89
 
91
- class Base(BaseClient):
92
- """Устаревший класс, используйте BaseClient!"""
93
- def __init_subclass__(cls, **kw):
94
- from warnings import warn
95
- warn("Class 'Base' renamed 'BaseClient' starting with version 2.4.6", DeprecationWarning)
96
- return BaseClient.__init_subclass__(**kw)
97
-
98
-
99
90
  class BasicAuthClient(BaseClient):
100
91
  """API клиент для авторизации `HTTP Basic`"""
101
92
 
102
- def _request(self, http_method: str, api_method: str, **kw) -> requests.Response:
93
+ def _request(self, http_method: str, api_method: str, **kw):
103
94
  if self._headers.get("Authorization") is None:
104
95
  auth_basic(None, None, client=self)
105
- return BaseClient._request(self, http_method, api_method, **kw)
96
+ return super()._request(http_method, api_method, **kw)
106
97
 
107
98
  @property
108
99
  def username(self) -> str:
@@ -127,9 +118,12 @@ class BasicAuthClient(BaseClient):
127
118
 
128
119
  class OfflineObjectBase(ms.ObjectBase):
129
120
  """API объект из словаря"""
121
+ _set_by_annotations = False
130
122
 
131
123
  def __init__(self, raw: dict, *args, **kwargs):
132
124
  self.raw = raw
125
+ if self._set_by_annotations:
126
+ _set_annotations(self)
133
127
  self._init(*args, **kwargs)
134
128
 
135
129
  def __getitem__(self, k):
@@ -144,8 +138,13 @@ class ObjectBase(OfflineObjectBase):
144
138
 
145
139
  def __init__(self, client: BaseClient, raw: dict, *args, **kwargs):
146
140
  self.client = client.client if isinstance(client, ObjectBase) else client
147
- self.raw = raw
148
- self._init(*args, **kwargs)
141
+ super().__init__(raw, *args, **kwargs)
142
+
143
+
144
+ def _set_annotations(obj: OfflineObjectBase):
145
+ for i in type(obj).__annotations__:
146
+ if not (i.startswith("_") or hasattr(obj, i)):
147
+ setattr(obj, i, obj[i])
149
148
 
150
149
 
151
150
  class CacheStorage(dict):
@@ -37,9 +37,11 @@ def make_insert_sql(table: str, values: dict, modifier=""):
37
37
  return f"INSERT {modifier}INTO {table} ({keys}) VALUES ({inserts});", list(values.values())
38
38
 
39
39
 
40
- def make_select_sql(table: str, columns: list[str], where: dict):
40
+ def make_select_sql(table: str, columns: str | list[str], where: dict):
41
41
  text, params = make_where_string(where)
42
- return f"SELECT {','.join(columns)} FROM {table} WHERE {text};", params
42
+ if not isinstance(columns, str):
43
+ columns = ','.join(columns)
44
+ return f"SELECT {columns} FROM {table} WHERE {text};", params
43
45
 
44
46
 
45
47
  def make_update_sql(table: str, values: dict, where: dict):
@@ -84,7 +86,7 @@ class Cursor(sqlite3.Cursor):
84
86
  def select_fetchone(self, table: str, columns: list[str], where: dict):
85
87
  return self.select(table, columns, where).fetchone()
86
88
 
87
- def select(self, table: str, columns: list[str], where: dict):
89
+ def select(self, table: str, columns: str | list[str], where: dict):
88
90
  """Выбрать строки из таблицы. Не выполняет `fetch`!"""
89
91
  return self.execute(*make_select_sql(table, columns, where))
90
92
 
@@ -28,7 +28,7 @@ class Database(DatabaseBase):
28
28
  kw["password"] = password
29
29
  kw["port"] = port
30
30
  kw["user"] = user
31
- DatabaseBase.__init__(self, **kw)
31
+ super().__init__(**kw)
32
32
  self.ConnectionError = (pymysql.err.OperationalError, ConnectionError)
33
33
 
34
34
  @classmethod
@@ -77,7 +77,7 @@ class Database(DatabaseBase):
77
77
  kw["password"] = password
78
78
  kw["port"] = port
79
79
  kw["user"] = user
80
- DatabaseBase.__init__(self, **kw)
80
+ super().__init__(**kw)
81
81
  self.ConnectionError = psycopg2.OperationalError, ConnectionError
82
82
 
83
83
  @classmethod
@@ -32,7 +32,7 @@ class Database(SyncDatabaseBase):
32
32
  self.db_path = Path(path)
33
33
  self.db_path.parent.any_mkdir()
34
34
  self.strict_schema = strict_schema
35
- DatabaseBase.__init__(self, **kw)
35
+ super().__init__(**kw)
36
36
  if TYPE_CHECKING:
37
37
  def cursor(self) -> Cursor:
38
38
  return super().cursor()
File without changes