mtbase 4.32.33__py3-none-any.whl → 4.32.35__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.
mt/aio/files.py CHANGED
@@ -10,7 +10,15 @@ import psutil
10
10
 
11
11
  from mt import ctx
12
12
 
13
- from .path import rename_asyn, rename, dirname, make_dirs, make_dirs_asyn
13
+ from .path import (
14
+ rename_asyn,
15
+ rename,
16
+ dirname,
17
+ make_dirs,
18
+ make_dirs_asyn,
19
+ exists_asyn,
20
+ remove_asyn,
21
+ )
14
22
 
15
23
 
16
24
  async def safe_chmod(filepath: str, file_mode: int = 0o664):
@@ -36,21 +44,21 @@ async def safe_rename(filepath: str, new_filepath: str, context_vars: dict = {})
36
44
  async def read_binary(filepath, size: int = None, context_vars: dict = {}) -> bytes:
37
45
  """An asyn function that opens a binary file and reads the content.
38
46
 
39
- Parameters
40
- ----------
41
- filepath : str
42
- path to the file
43
- size : int
44
- size to read from the beginning of the file, in bytes. If None is given, read the whole
45
- file.
46
- context_vars : dict
47
- a dictionary of context variables within which the function runs. It must include
48
- `context_vars['async']` to tell whether to invoke the function asynchronously or not.
49
-
50
- Returns
51
- -------
52
- bytes
53
- the content read from file
47
+ Parameters
48
+ s ----------
49
+ filepath : str
50
+ path to the file
51
+ size : int
52
+ size to read from the beginning of the file, in bytes. If None is given, read the whole
53
+ file.
54
+ context_vars : dict
55
+ a dictionary of context variables within which the function runs. It must include
56
+ `context_vars['async']` to tell whether to invoke the function asynchronously or not.
57
+
58
+ Returns
59
+ -------
60
+ bytes
61
+ the content read from file
54
62
  """
55
63
 
56
64
  for i in range(3):
@@ -119,12 +127,16 @@ async def write_binary(
119
127
  if make_dirs:
120
128
  dirpath = dirname(filepath)
121
129
  await make_dirs_asyn(dirpath, context_vars=context_vars)
122
- filepath2 = filepath + ".mttmp"
123
- async with aiofiles.open(filepath2, mode="wb") as f:
124
- retval = await f.write(buf)
125
- if file_mode is not None: # chmod
126
- await safe_chmod(filepath2, file_mode=file_mode)
127
- await safe_rename(filepath2, filepath, context_vars=context_vars)
130
+ try:
131
+ filepath2 = filepath + ".mttmp"
132
+ async with aiofiles.open(filepath2, mode="wb") as f:
133
+ retval = await f.write(buf)
134
+ if file_mode is not None: # chmod
135
+ await safe_chmod(filepath2, file_mode=file_mode)
136
+ await safe_rename(filepath2, filepath, context_vars=context_vars)
137
+ finally:
138
+ if await exists_asyn(filepath2, context_vars=context_vars):
139
+ await remove_asyn(filepath2, context_vars=context_vars)
128
140
  return retval
129
141
 
130
142
  coro = func(filepath, buf, file_mode)
@@ -213,12 +225,16 @@ async def write_text(
213
225
  if make_dirs:
214
226
  dirpath = dirname(filepath)
215
227
  await make_dirs_asyn(dirpath, context_vars=context_vars)
216
- filepath2 = filepath + ".mttmp"
217
- async with aiofiles.open(filepath2, mode="wt") as f:
218
- retval = await f.write(buf)
219
- if file_mode is not None: # chmod
220
- await safe_chmod(filepath2, file_mode=file_mode)
221
- await safe_rename(filepath2, filepath, context_vars=context_vars)
228
+ try:
229
+ filepath2 = filepath + ".mttmp"
230
+ async with aiofiles.open(filepath2, mode="wt") as f:
231
+ retval = await f.write(buf)
232
+ if file_mode is not None: # chmod
233
+ await safe_chmod(filepath2, file_mode=file_mode)
234
+ await safe_rename(filepath2, filepath, context_vars=context_vars)
235
+ finally:
236
+ if await exists_asyn(filepath2, context_vars=context_vars):
237
+ await remove_asyn(filepath2, context_vars=context_vars)
222
238
  return retval
223
239
 
224
240
  coro = func(filepath, buf, file_mode)
mt/base/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  MAJOR_VERSION = 4
2
2
  MINOR_VERSION = 32
3
- PATCH_VERSION = 33
3
+ PATCH_VERSION = 35
4
4
  version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
5
5
  __all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version']
mt/traceback/__init__.py CHANGED
@@ -22,6 +22,7 @@ Please see Python package `traceback`_ for more details.
22
22
 
23
23
  import traceback as _tb
24
24
  import asyncio
25
+ import linecache
25
26
  from traceback import *
26
27
 
27
28
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mtbase
3
- Version: 4.32.33
3
+ Version: 4.32.35
4
4
  Summary: The most fundamental Python modules for Minh-Tri Pham
5
5
  Home-page: https://github.com/inteplus/mtbase
6
6
  Author: ['Minh-Tri Pham']
@@ -1,6 +1,6 @@
1
1
  mt/aio/__init__.py,sha256=-k13vDemo1Onk3yPWv86zav4HAnimvLVpXdH2mkXRJc,2202
2
2
  mt/aio/base.py,sha256=HE97hmtjHcxA2t_gd4AZ4e5mlRd4lIGY5jY_f65pdPg,3982
3
- mt/aio/files.py,sha256=tjF4kBsrZ35Jon_UfE0nCN3CiQFddZFNDOvXAKUmlDk,13835
3
+ mt/aio/files.py,sha256=9b4iHJXZRssukX7cEXEKp2eMf7KKnDQ37HgzKW3ao-g,14379
4
4
  mt/aio/multiprocessing.py,sha256=G43P7bN10J7UqTYCsa1eh3VatJWEbLEqg1xNK3MKWdk,8978
5
5
  mt/aio/path.py,sha256=d-zE88pTD65-KskLi6j_1Hdys7NXrDOOmHqUyHYxehY,10041
6
6
  mt/aio/procedure.py,sha256=eJ4AtCxqvDDxGrz-Pycred1CJRfD60VPvjUaaJ0OhYM,3323
@@ -25,7 +25,7 @@ mt/base/s3.py,sha256=dt-ph2pBv2oplddlRHCkbP58i4P-g60US6DhC4vAKAA,20083
25
25
  mt/base/str.py,sha256=_R1GRJG8XEfUwabz_dsMD-g0zf3bF4b41_L3vXmiI0o,3580
26
26
  mt/base/terminal.py,sha256=_23Kk7oihgCbe2yjJw2SQrTCqymSi-drejn1SWIS6IY,104
27
27
  mt/base/threading.py,sha256=MTVjpaTg_sbZWCksoP_5iMVYFjjUxrgpYBMOWxFY4Ms,110
28
- mt/base/version.py,sha256=gadNR2bqSX7kjDBLjutv0pQPT_7rlSZEnR7-r0o_Pbs,208
28
+ mt/base/version.py,sha256=kmye44k0WI8tqeDZKrgjppHA2U9PeyW1IdZ4ol6ZY7c,208
29
29
  mt/base/zipfile.py,sha256=SnsBCaPlPw300_mi7WYB6wSqjvW-U_g96vS2S9JwrnE,1765
30
30
  mt/concurrency/__init__.py,sha256=jF7NoWRKap-QhuJaJZ3EUpfrn2HaZa_8MAS0bT325AY,428
31
31
  mt/concurrency/aio.py,sha256=efStmaQ6JkqdS7fQTcvCmOVH3ylqyKsEG8tjXhZQIZs,24785
@@ -56,11 +56,11 @@ mt/shutil/__init__.py,sha256=PW9_pxVH3EVdxETupRoFc5StyyS8A8LX1lRFGVr8I4A,990
56
56
  mt/threading/__init__.py,sha256=dE7YEfeBMyxJ1DzFox28r0e2CzsSMWtm2XCvyk_ewXg,4994
57
57
  mt/time/__init__.py,sha256=lAjC0En0X0spHTu2YC120AchNlv1SzHgQlX0RmXWLEc,2158
58
58
  mt/tp/__init__.py,sha256=TvEzpRQpi8eKdt-mGhX6mgkY3V4zB-0RWNf-BiRm1vU,633
59
- mt/traceback/__init__.py,sha256=4WUtGbPklLM9s-jlQQrQiFuEaTbKQKeV1DEzRj_HfYY,3648
59
+ mt/traceback/__init__.py,sha256=Dnl2pYS3WvwwU5BPZmZY7-IBtfwliqyxTQUK0Zge8eA,3665
60
60
  mt/v4l2/__init__.py,sha256=s5a0Ve3QI0I2F2q192qLKfw8dPvcrHRy1JCdpMQz8cE,870
61
- mtbase-4.32.33.data/scripts/path_exists,sha256=9rYAZNiVEeTTi-hKM8NkQVIZOaEQkWE_WVw72avfUDo,690
62
- mtbase-4.32.33.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
63
- mtbase-4.32.33.dist-info/METADATA,sha256=ob6x73Ti1zuUcxdAWVQhVA_FqasObtkRG-I8AGr_dgM,806
64
- mtbase-4.32.33.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
- mtbase-4.32.33.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
66
- mtbase-4.32.33.dist-info/RECORD,,
61
+ mtbase-4.32.35.data/scripts/path_exists,sha256=9rYAZNiVEeTTi-hKM8NkQVIZOaEQkWE_WVw72avfUDo,690
62
+ mtbase-4.32.35.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
63
+ mtbase-4.32.35.dist-info/METADATA,sha256=16QSbfENXEYMzt8RBfCdpmuRLC1olHejRfjSuqdtUkI,806
64
+ mtbase-4.32.35.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
+ mtbase-4.32.35.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
66
+ mtbase-4.32.35.dist-info/RECORD,,