ramifice 0.8.3__py3-none-any.whl → 0.8.4__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.
@@ -1,12 +1,13 @@
1
1
  """Field of Model for upload file."""
2
2
 
3
- import os
4
3
  import uuid
5
4
  from base64 import b64decode
6
5
  from datetime import date
6
+ from os.path import basename
7
7
  from pathlib import Path
8
8
 
9
- import aiofiles
9
+ from aiofiles import open as async_open
10
+ from aiofiles import os as async_os
10
11
  from aioshutil import copyfile
11
12
 
12
13
  from ramifice.fields.general.field import Field
@@ -127,12 +128,12 @@ class FileField(Field, FileGroup, JsonMixin):
127
128
  # Create path to target directory.
128
129
  dir_target_path = f"{MEDIA_ROOT}/uploads/{self.target_dir}/{date_str}"
129
130
  # Create target directory if it does not exist.
130
- if not await aiofiles.os.path.exists(dir_target_path):
131
- await aiofiles.os.makedirs(dir_target_path)
131
+ if not await async_os.path.exists(dir_target_path):
132
+ await async_os.makedirs(dir_target_path)
132
133
  # Create path to target file.
133
134
  f_target_path = f"{dir_target_path}/{f_uuid_name}"
134
135
  # Save file in target directory.
135
- async with aiofiles.open(f_target_path, mode="wb") as open_f:
136
+ async with async_open(f_target_path, mode="wb") as open_f:
136
137
  f_content = b64decode(base64_str)
137
138
  await open_f.write(f_content)
138
139
  # Add paths to target file.
@@ -143,7 +144,7 @@ class FileField(Field, FileGroup, JsonMixin):
143
144
  # Add file extension.
144
145
  file_info["extension"] = extension
145
146
  # Add file size (in bytes).
146
- file_info["size"] = await aiofiles.os.path.getsize(f_target_path)
147
+ file_info["size"] = await async_os.path.getsize(f_target_path)
147
148
  #
148
149
  # to value.
149
150
  self.value = file_info
@@ -172,8 +173,8 @@ class FileField(Field, FileGroup, JsonMixin):
172
173
  # Create path to target directory.
173
174
  dir_target_path = f"{MEDIA_ROOT}/uploads/{self.target_dir}/{date_str}"
174
175
  # Create target directory if it does not exist.
175
- if not await aiofiles.os.path.exists(dir_target_path):
176
- await aiofiles.os.makedirs(dir_target_path)
176
+ if not await async_os.path.exists(dir_target_path):
177
+ await async_os.makedirs(dir_target_path)
177
178
  # Create path to target file.
178
179
  f_target_path = f"{dir_target_path}/{f_uuid_name}"
179
180
  # Save file in target directory.
@@ -182,11 +183,11 @@ class FileField(Field, FileGroup, JsonMixin):
182
183
  file_info["path"] = f_target_path
183
184
  file_info["url"] = f"{MEDIA_URL}/uploads/{self.target_dir}/{date_str}/{f_uuid_name}"
184
185
  # Add original file name.
185
- file_info["name"] = os.path.basename(src_path)
186
+ file_info["name"] = basename(src_path)
186
187
  # Add file extension.
187
188
  file_info["extension"] = extension
188
189
  # Add file size (in bytes).
189
- file_info["size"] = await aiofiles.os.path.getsize(f_target_path)
190
+ file_info["size"] = await async_os.path.getsize(f_target_path)
190
191
  #
191
192
  # to value.
192
193
  self.value = file_info
@@ -1,12 +1,13 @@
1
1
  """Field of Model for upload image."""
2
2
 
3
- import os
4
3
  import uuid
5
4
  from base64 import b64decode
6
5
  from datetime import date
6
+ from os.path import basename
7
7
  from pathlib import Path
8
8
 
9
- import aiofiles
9
+ from aiofiles import open as async_open
10
+ from aiofiles import os as async_os
10
11
  from aioshutil import copyfile
11
12
 
12
13
  from ramifice.fields.general.field import Field
@@ -164,10 +165,10 @@ class ImageField(Field, FileGroup, JsonMixin):
164
165
  # Create path to main image.
165
166
  main_img_path = f"{imgs_dir_path}/{new_original_name}"
166
167
  # Create target directory if it does not exist.
167
- if not await aiofiles.os.path.exists(imgs_dir_path):
168
- await aiofiles.os.makedirs(imgs_dir_path)
168
+ if not await async_os.path.exists(imgs_dir_path):
169
+ await async_os.makedirs(imgs_dir_path)
169
170
  # Save main image in target directory.
170
- async with aiofiles.open(main_img_path, mode="wb") as open_f:
171
+ async with async_open(main_img_path, mode="wb") as open_f:
171
172
  f_content = b64decode(base64_str)
172
173
  await open_f.write(f_content)
173
174
  # Add paths for main image.
@@ -187,7 +188,7 @@ class ImageField(Field, FileGroup, JsonMixin):
187
188
  # Add url path to target directory with images.
188
189
  img_info["imgs_dir_url"] = imgs_dir_url
189
190
  # Add size of main image (in bytes).
190
- img_info["size"] = await aiofiles.os.path.getsize(main_img_path)
191
+ img_info["size"] = await async_os.path.getsize(main_img_path)
191
192
  #
192
193
  # to value.
193
194
  self.value = img_info
@@ -222,15 +223,15 @@ class ImageField(Field, FileGroup, JsonMixin):
222
223
  # Create path to main image.
223
224
  main_img_path = f"{imgs_dir_path}/{new_original_name}"
224
225
  # Create target directory if it does not exist.
225
- if not await aiofiles.os.path.exists(imgs_dir_path):
226
- await aiofiles.os.makedirs(imgs_dir_path)
226
+ if not await async_os.path.exists(imgs_dir_path):
227
+ await async_os.makedirs(imgs_dir_path)
227
228
  # Save main image in target directory.
228
229
  await copyfile(src_path, main_img_path)
229
230
  # Add paths for main image.
230
231
  img_info["path"] = main_img_path
231
232
  img_info["url"] = f"{imgs_dir_url}/{new_original_name}"
232
233
  # Add original image name.
233
- img_info["name"] = os.path.basename(src_path)
234
+ img_info["name"] = basename(src_path)
234
235
  # Add image extension.
235
236
  img_info["extension"] = extension
236
237
  # Transform extension to the upper register and delete the point.
@@ -243,7 +244,7 @@ class ImageField(Field, FileGroup, JsonMixin):
243
244
  # Add url path to target directory with images.
244
245
  img_info["imgs_dir_url"] = imgs_dir_url
245
246
  # Add size of main image (in bytes).
246
- img_info["size"] = await aiofiles.os.path.getsize(main_img_path)
247
+ img_info["size"] = await async_os.path.getsize(main_img_path)
247
248
  #
248
249
  # to value.
249
250
  self.value = img_info
@@ -42,6 +42,7 @@ def model(
42
42
  raise DoesNotMatchRegexError("^[A-Z][a-zA-Z0-9]{0,24}$")
43
43
  if fixture_name is not None:
44
44
  fixture_path = f"config/fixtures/{fixture_name}.yml"
45
+
45
46
  if not os.path.exists(fixture_path):
46
47
  msg = (
47
48
  f"Model: `{cls.__module__}.{cls.__name__}` > "
@@ -2,7 +2,7 @@
2
2
 
3
3
  from typing import Any
4
4
 
5
- from aiofiles import os
5
+ from aiofiles import os as async_os
6
6
  from aioshutil import rmtree
7
7
  from bson.objectid import ObjectId
8
8
  from pymongo.asynchronous.collection import AsyncCollection
@@ -133,7 +133,7 @@ class CheckMixin(
133
133
  file_data = result_map.get(field_name)
134
134
  if file_data is not None:
135
135
  if file_data["is_new_file"]:
136
- await os.remove(file_data["path"])
136
+ await async_os.remove(file_data["path"])
137
137
  field_data.value = None
138
138
  if curr_doc is not None:
139
139
  field_data.value = curr_doc[field_name]
@@ -2,7 +2,7 @@
2
2
 
3
3
  from typing import Any
4
4
 
5
- from aiofiles import os
5
+ from aiofiles import os as async_os
6
6
  from aioshutil import rmtree
7
7
  from pymongo.asynchronous.collection import AsyncCollection
8
8
 
@@ -77,7 +77,7 @@ class DeleteMixin:
77
77
  if group == "file":
78
78
  file_data = mongo_doc[field_name]
79
79
  if file_data is not None and len(file_data["path"]) > 0:
80
- await os.remove(file_data["path"])
80
+ await async_os.remove(file_data["path"])
81
81
  file_data = None
82
82
  elif group == "img":
83
83
  file_data = mongo_doc[field_name]
ramifice/utils/tools.py CHANGED
@@ -3,11 +3,11 @@
3
3
  import asyncio
4
4
  import ipaddress
5
5
  import math
6
- import os
7
6
  from typing import Any
8
7
  from urllib.parse import urlparse
9
8
 
10
9
  import phonenumbers
10
+ from aiofiles import ospath
11
11
  from bson.objectid import ObjectId
12
12
  from email_validator import EmailNotValidError, validate_email
13
13
 
@@ -29,9 +29,9 @@ def to_human_size(size: int) -> str:
29
29
  return f"{size} {order}"
30
30
 
31
31
 
32
- def get_file_size(path: str) -> int:
32
+ async def get_file_size(path: str) -> int:
33
33
  """Get file size in bytes."""
34
- size: int = os.path.getsize(path)
34
+ size: int = await ospath.getsize(path)
35
35
  return size
36
36
 
37
37
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ramifice
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: ORM-like API MongoDB for Python language.
5
5
  Project-URL: Homepage, https://github.com/kebasyaty/ramifice
6
6
  Project-URL: Documentation, https://kebasyaty.github.io/ramifice/
@@ -25,10 +25,10 @@ ramifice/fields/color_field.py,sha256=K-lYp8f08HTZt6WU0kY3CQWaAmx6I3-uyKHBq7xAeS
25
25
  ramifice/fields/date_field.py,sha256=-M_dD8tVUXcDCQD5Hy5Ns9Z2QGlRya0qbvoWgA4qpmg,5277
26
26
  ramifice/fields/date_time_field.py,sha256=ahjX-cD5Qj-V7JUi5QAZ8qgv9UePhYYYzJghiasKdqE,5312
27
27
  ramifice/fields/email_field.py,sha256=4Kxy1K6CXJUJ8Db0CQuopjodiY4ybe7V0GT756t7Nks,3481
28
- ramifice/fields/file_field.py,sha256=jYAiP0KmhsrjJwVgEHUCA0zqJzKZmjFw9OeXv583ln0,8202
28
+ ramifice/fields/file_field.py,sha256=CSCHSExyXUsvLGGCj3WmBHM0YUUcK9QZZb3kB8r8HQs,8253
29
29
  ramifice/fields/float_field.py,sha256=JeVwoIi6j-dovXarZ3NgmSQI7f3qZzydlRs_yqp3Faw,4637
30
30
  ramifice/fields/id_field.py,sha256=YO5oIwXtqgURjjd2oYe2ouXxdpaiJp5ZhUgUA2pkNeo,4183
31
- ramifice/fields/image_field.py,sha256=g3z_Ug5Ob514OZdacm6qpHTRpPBauuL3WqBTfQgEO1I,11621
31
+ ramifice/fields/image_field.py,sha256=ZBbraEI0P5qWK1_xDnZ42YXhqgK4LdcL28vg9zgPBiw,11672
32
32
  ramifice/fields/integer_field.py,sha256=xPwpdhYNz4MyHgOypqa29oGNdKZic05yyUYHg5CDD3E,4609
33
33
  ramifice/fields/ip_field.py,sha256=tBFGFMC_zwAyLGtVRNNfiu4vQoxXPcgVHhX_aoHrvns,3390
34
34
  ramifice/fields/password_field.py,sha256=USD4Y8MTI89QZVT6zqLGBmb5kqOKrXqh73-z99cOvtk,3266
@@ -44,11 +44,11 @@ ramifice/fields/general/file_group.py,sha256=pC9bGUpDeu7FLJVD6NMCzq18aPETotipknS
44
44
  ramifice/fields/general/number_group.py,sha256=LOPHbKAnIuqW4DEh2fH78w6qOQjp0OhkuP7MoikhlkA,761
45
45
  ramifice/fields/general/text_group.py,sha256=m9EnlYGwqlck-JIYOCUd0hUYAVr8jH4YCnTmm9QlCkQ,1103
46
46
  ramifice/models/__init__.py,sha256=h_QQ5rSJNZ-7kmx7wIFd8E8RmUS94b_x4jdwMbq8zm4,15
47
- ramifice/models/decorator.py,sha256=fL9xc7-_BEiFEqfwgql6CihYWB6MC-JgiC0FSSK_JHA,5956
47
+ ramifice/models/decorator.py,sha256=dzwC489KBjamQxrWNy8lrdXVLb3e8OKPWbPGJZqxaFA,5958
48
48
  ramifice/models/model.py,sha256=e5UWHKIHwm7saxQ4bbamsTkz1VVBIqTRlAmJCOg5uRE,7160
49
49
  ramifice/paladins/__init__.py,sha256=EJ6EEKXUcMG5P1bDmlEa4W3fsxSz5u6mzDG_oU1efMQ,618
50
- ramifice/paladins/check.py,sha256=9lLJ6SnNQBI9eyAwWSqjFa7_F2A2QbTg4WHyrPL3E20,6584
51
- ramifice/paladins/delete.py,sha256=90ZiTzYxa2bnhOJhkEBe7XR_Yi4gaTvrJ3u4dSik0mU,3430
50
+ ramifice/paladins/check.py,sha256=c-7jbFV5qzE9nF8Cl6VSPA8DtziADOuV6j1rldnZBKI,6602
51
+ ramifice/paladins/delete.py,sha256=teUyj-sosObatoaFpMC3wodC4GvWbzgJCCxsI_Z9vyk,3448
52
52
  ramifice/paladins/password.py,sha256=G-tMz2dIiOYEhOeSHYgAmc2e4tG_TJ2gt5tzPwBapkw,3047
53
53
  ramifice/paladins/refrash.py,sha256=hIZQEBGtoIhuGGg2KQYGApCaMb8WhK_QZlzi1_-zzU0,1100
54
54
  ramifice/paladins/save.py,sha256=mFau65uWYy4dSVyTVdZGR3VUnP-I_NPdMvq7F5n1sFo,3899
@@ -70,7 +70,7 @@ ramifice/utils/constants.py,sha256=dTSk07FVc6hgXwG1IF0_klPnbfxlFHiaRmym5zWgzIM,2
70
70
  ramifice/utils/errors.py,sha256=iuhq7fzpUmsOyeXeg2fJjta8yAuqlXLKsZVMpfUhtHE,1901
71
71
  ramifice/utils/fixtures.py,sha256=PMRl1Ud0Ek0eX5F7BPiL7az_H7YKtIVKB8MJ17CeBdw,3179
72
72
  ramifice/utils/migration.py,sha256=5VYYB7DFMzLCRYWdlwtqGRSUPFdXp5SMxuMWraofVCw,11106
73
- ramifice/utils/tools.py,sha256=dJjG92nevSq_US30pUdbBy37pvqBdxXHBeHZxpOInKM,2843
73
+ ramifice/utils/tools.py,sha256=DSSR__sHgfDlYF4vhtR8vmeFtgquonkM5W_3V3SX6Y0,2872
74
74
  ramifice/utils/translations.py,sha256=Ibx6HqPcnsNxuBfXDs9mCLEA7xu4mkl3q39vqFaK-GI,4233
75
75
  ramifice/utils/unit.py,sha256=PPNKWYFJ8cz0nwbBPaTdL58_Nr7N0fIHFJBpKG2ZLKI,2482
76
76
  ramifice/utils/mixins/__init__.py,sha256=GrxJDsw73bEkitIh0-0BCxNnUK-N5uRXMCRlaPoaz1o,265
@@ -78,7 +78,7 @@ ramifice/utils/mixins/add_valid.py,sha256=TLOObedzXNA9eCylfAVbVCqIKE5sV-P5AdIN7a
78
78
  ramifice/utils/mixins/hooks.py,sha256=33jvJRhfnJeL2Hd_YFXk3M_7wjqHaByU2wRjKyboL6s,914
79
79
  ramifice/utils/mixins/indexing.py,sha256=Z0427HoaVRyNmSNN8Fx0mSICgAKV-gDdu3iR5qYUEbs,329
80
80
  ramifice/utils/mixins/json_converter.py,sha256=2K_PZ34AzpesusgyyQFOLXFPcjXez3TWn-m9CHIKwRo,1131
81
- ramifice-0.8.3.dist-info/METADATA,sha256=oPmjSfAlrM-Uf-jeztkvHapDj1HkLptyEvwiPZkLrO4,21016
82
- ramifice-0.8.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
83
- ramifice-0.8.3.dist-info/licenses/LICENSE,sha256=LrEL0aTZx90HDwFUQCJutORiDjJL9AnuVvCtspXIqt4,1095
84
- ramifice-0.8.3.dist-info/RECORD,,
81
+ ramifice-0.8.4.dist-info/METADATA,sha256=D7LCsTfcUITuLa2XzN_DS5sSgED6Scv9JfaXcu5b84k,21016
82
+ ramifice-0.8.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
83
+ ramifice-0.8.4.dist-info/licenses/LICENSE,sha256=LrEL0aTZx90HDwFUQCJutORiDjJL9AnuVvCtspXIqt4,1095
84
+ ramifice-0.8.4.dist-info/RECORD,,