MainShortcuts2 2.8.3__tar.gz → 2.8.4__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 (56) hide show
  1. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/PKG-INFO +1 -1
  2. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/pyproject.toml +1 -1
  3. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/_module_info.py +1 -1
  4. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/pathlib_ex.py +41 -9
  5. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ms2dat1.py +9 -2
  6. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/README.md +0 -0
  7. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/__init__.py +0 -0
  8. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/__main__.py +0 -0
  9. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/_any2json_regs.py +0 -0
  10. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/_ms2app_regs.py +0 -0
  11. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/_ms2dat_auto.py +0 -0
  12. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/advanced.py +0 -0
  13. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/any2json.py +0 -0
  14. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/api/base.py +0 -0
  15. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/api/gigachat.py +0 -0
  16. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/api/github.py +0 -0
  17. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/api/russian_trusted_root_ca_pem.crt +0 -0
  18. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/api/russian_trusted_sub_ca_pem.crt +0 -0
  19. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/api/webdav.py +0 -0
  20. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/cfg.py +0 -0
  21. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/core.py +0 -0
  22. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/core_config.py +0 -0
  23. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/dict.py +0 -0
  24. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/dir.py +0 -0
  25. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/__init__.py +0 -0
  26. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/aiohttp_ex/web/__init__.py +0 -0
  27. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/aiohttp_ex/web/__main__.py +0 -0
  28. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/datetime_ex.py +0 -0
  29. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/pil_ex.py +0 -0
  30. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/psutil_ex.py +0 -0
  31. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/sqlite_ex.py +0 -0
  32. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ex/urlparse_ex.py +0 -0
  33. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/file.py +0 -0
  34. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/gui_scripts/__init__.py +0 -0
  35. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/gui_scripts/ms2_hash_gen.py +0 -0
  36. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/gui_scripts/utils.py +0 -0
  37. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/java_ext/__init__.py +0 -0
  38. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/java_ext/ms2ext.py +0 -0
  39. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/json.py +0 -0
  40. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/linux.py +0 -0
  41. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/list.py +0 -0
  42. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ms2app.py +0 -0
  43. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/ms2hash.py +0 -0
  44. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/path.py +0 -0
  45. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/proc.py +0 -0
  46. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/regex.py +0 -0
  47. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/special_chars.py +0 -0
  48. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/sql/_sql_base.py +0 -0
  49. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/sql/mysql.py +0 -0
  50. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/sql/postgresql.py +0 -0
  51. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/sql/sqlite.py +0 -0
  52. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/str.py +0 -0
  53. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/term.py +0 -0
  54. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/types.py +0 -0
  55. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/utils.py +0 -0
  56. {mainshortcuts2-2.8.3 → mainshortcuts2-2.8.4}/src/MainShortcuts2/win.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MainShortcuts2
3
- Version: 2.8.3
3
+ Version: 2.8.4
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.8.3"
2
+ version = "2.8.4"
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.8.3'
2
+ version = '2.8.4'
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import pathlib
3
3
  import shutil
4
+ import typing
4
5
  from MainShortcuts2 import ms
5
6
  from os import fspath
6
7
  from stat import S_ISDIR, S_ISREG
@@ -12,7 +13,7 @@ class Path(pathlib.Path):
12
13
  """Объект `ms.path.Path`"""
13
14
  return ms.path.Path(self)
14
15
 
15
- def size(self, recursive=False, **walk_kw):
16
+ def size(self, recursive=False, **walk_kw) -> int:
16
17
  """Вычислить размер файла/папки"""
17
18
  st = self.stat()
18
19
  if S_ISREG(st.st_mode):
@@ -56,7 +57,7 @@ class Path(pathlib.Path):
56
57
  def _get_write_path(self):
57
58
  """tmp,real"""
58
59
  real = self.resolve()
59
- tmp = real
60
+ tmp = real.with_name(self.name + ".tmp" + ms.utils.randstr(4))
60
61
  while tmp.exists():
61
62
  tmp = real.with_name(self.name + ".tmp" + ms.utils.randstr(4))
62
63
  return tmp, real
@@ -71,18 +72,24 @@ class Path(pathlib.Path):
71
72
  kw.setdefault("encoding", "utf-8")
72
73
  """Записать текст в файл"""
73
74
  tmp, real = self._get_write_path()
74
- with tmp.open("w", **kw) as f:
75
- result = f.write(data)
76
- if not tmp.samefile(real):
75
+ try:
76
+ with tmp.open("w", **kw) as f:
77
+ result = f.write(data)
77
78
  tmp.replace(real)
79
+ except:
80
+ tmp.unlink(True)
81
+ raise
78
82
  return result
79
83
 
80
- def write_bytes(self, data, **kw) -> int:
84
+ def write_bytes(self, data: bytes, **kw) -> int:
81
85
  tmp, real = self._get_write_path()
82
- with tmp.open("wb", **kw) as f:
83
- result = f.write(data)
84
- if not tmp.samefile(real):
86
+ try:
87
+ with tmp.open("wb", **kw) as f:
88
+ result = f.write(data)
85
89
  tmp.replace(real)
90
+ except:
91
+ tmp.unlink(True)
92
+ raise
86
93
  return result
87
94
 
88
95
  def read_json(self, **kw):
@@ -140,3 +147,28 @@ class Path(pathlib.Path):
140
147
  yield from [os.path.join(root, i) for i in filenames]
141
148
  else:
142
149
  yield from os.listdir(self)
150
+ if not typing.TYPE_CHECKING:
151
+ def samefile(self, other_path):
152
+ """Добавление проверки пути к файлу, чтобы не выполнять stat лишний раз"""
153
+ if os.fspath(self) == os.fspath(other_path):
154
+ return True
155
+ return super().samefile(other_path)
156
+
157
+ def samestat(self, st2: os.stat_result):
158
+ """Аналогично `.samefile`, но принимает `stat_result` вместо пути"""
159
+ st1 = self.stat()
160
+ return st1.st_dev == st2.st_dev and st1.st_ino == st2.st_ino
161
+
162
+ def write_ms2dat(self, data, **kw):
163
+ """Сохранить данные в последней версии формата MS2Dat"""
164
+ ms.ms2dat.write_file(data, self, **kw)
165
+
166
+ def write_ms2dat_v1(self, data, ms2dat_inst=None, **kw):
167
+ """Сохранить данные в формате MS2Dat v1"""
168
+ if ms2dat_inst is None:
169
+ ms2dat_inst = ms.ms2dat_v1.inst
170
+ ms2dat_inst.write_file(data, self, **kw)
171
+
172
+ def read_ms2dat(self, **kw):
173
+ """Прочитать данные в формате MS2Dat"""
174
+ ms.ms2dat.read_file(self, **kw)
@@ -6,6 +6,7 @@ import struct
6
6
  import typing
7
7
  import uuid
8
8
  from io import BytesIO
9
+ from MainShortcuts2.ex.pathlib_ex import Path
9
10
  from MainShortcuts2.utils import int_size_unsigned
10
11
  HASH_NAMES = None, "sha256", "sha3-256", "sha512"
11
12
  HASH_SIZES = 0, 32, 32, 64
@@ -516,8 +517,14 @@ class MS2Dat1:
516
517
 
517
518
  def write_file(self, obj, path, **kw):
518
519
  """Сохранить объект в локальный файл"""
519
- with open(path, "wb") as f:
520
- self.dump(obj, f, **kw)
520
+ tmp, real = Path(path)._get_write_path()
521
+ try:
522
+ with tmp.open("wb") as f:
523
+ self.dump(obj, f, **kw)
524
+ tmp.replace(real)
525
+ except:
526
+ tmp.unlink(True)
527
+ raise
521
528
 
522
529
 
523
530
  class MS2Dat1EncryptExample(MS2Dat1):
File without changes