abstract-utilities 0.2.2.627__py3-none-any.whl → 0.2.2.700__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.
Files changed (42) hide show
  1. abstract_utilities/__init__.py +7 -3
  2. abstract_utilities/class_utils/abstract_classes.py +104 -34
  3. abstract_utilities/class_utils/caller_utils.py +38 -0
  4. abstract_utilities/class_utils/imports/imports.py +1 -1
  5. abstract_utilities/file_utils/imports/classes.py +59 -55
  6. abstract_utilities/file_utils/imports/module_imports.py +1 -1
  7. abstract_utilities/file_utils/src/file_filters/__init__.py +0 -3
  8. abstract_utilities/file_utils/src/file_filters/ensure_utils.py +382 -10
  9. abstract_utilities/file_utils/src/file_filters/filter_params.py +64 -0
  10. abstract_utilities/file_utils/src/file_filters/predicate_utils.py +2 -74
  11. abstract_utilities/file_utils/src/find_collect.py +10 -0
  12. abstract_utilities/import_utils/imports/__init__.py +1 -1
  13. abstract_utilities/import_utils/imports/init_imports.py +3 -0
  14. abstract_utilities/import_utils/imports/module_imports.py +1 -0
  15. abstract_utilities/import_utils/imports/utils.py +1 -1
  16. abstract_utilities/import_utils/src/__init__.py +1 -0
  17. abstract_utilities/import_utils/src/import_utils.py +39 -0
  18. abstract_utilities/import_utils/src/layze_import_utils/__init__.py +2 -0
  19. abstract_utilities/import_utils/src/layze_import_utils/lazy_utils.py +41 -0
  20. abstract_utilities/import_utils/src/layze_import_utils/nullProxy.py +37 -0
  21. abstract_utilities/import_utils/src/nullProxy.py +30 -0
  22. abstract_utilities/imports.py +5 -2
  23. abstract_utilities/json_utils/imports/imports.py +1 -1
  24. abstract_utilities/json_utils/json_utils.py +37 -3
  25. abstract_utilities/list_utils/list_utils.py +3 -0
  26. abstract_utilities/log_utils/log_file.py +82 -27
  27. abstract_utilities/path_utils/imports/module_imports.py +1 -1
  28. abstract_utilities/path_utils/path_utils.py +7 -12
  29. abstract_utilities/read_write_utils/read_write_utils.py +63 -30
  30. abstract_utilities/type_utils/__init__.py +5 -1
  31. abstract_utilities/type_utils/get_type.py +120 -0
  32. abstract_utilities/type_utils/imports/__init__.py +1 -0
  33. abstract_utilities/type_utils/imports/constants.py +134 -0
  34. abstract_utilities/type_utils/imports/module_imports.py +25 -1
  35. abstract_utilities/type_utils/is_type.py +455 -0
  36. abstract_utilities/type_utils/make_type.py +126 -0
  37. abstract_utilities/type_utils/mime_types.py +68 -0
  38. abstract_utilities/type_utils/type_utils.py +0 -877
  39. {abstract_utilities-0.2.2.627.dist-info → abstract_utilities-0.2.2.700.dist-info}/METADATA +1 -1
  40. {abstract_utilities-0.2.2.627.dist-info → abstract_utilities-0.2.2.700.dist-info}/RECORD +42 -32
  41. {abstract_utilities-0.2.2.627.dist-info → abstract_utilities-0.2.2.700.dist-info}/WHEEL +0 -0
  42. {abstract_utilities-0.2.2.627.dist-info → abstract_utilities-0.2.2.700.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,134 @@
1
+ from .module_imports import *
2
+ MIME_TYPES = {
3
+ 'image': {
4
+ '.jpg': 'image/jpeg',
5
+ '.jpeg': 'image/jpeg',
6
+ '.png': 'image/png',
7
+ '.gif': 'image/gif',
8
+ '.bmp': 'image/bmp',
9
+ '.tiff': 'image/tiff',
10
+ '.webp': 'image/webp',
11
+ '.svg': 'image/svg+xml',
12
+ '.ico': 'image/vnd.microsoft.icon',
13
+ '.heic': 'image/heic',
14
+ '.psd': 'image/vnd.adobe.photoshop',
15
+ '.raw': 'image/x-raw',
16
+ },
17
+ 'video': {
18
+ '.mp4': 'video/mp4',
19
+ '.webm': 'video/webm',
20
+ '.ogg': 'video/ogg',
21
+ '.mov': 'video/quicktime',
22
+ '.avi': 'video/x-msvideo',
23
+ '.mkv': 'video/x-matroska',
24
+ '.flv': 'video/x-flv',
25
+ '.wmv': 'video/x-ms-wmv',
26
+ '.3gp': 'video/3gpp',
27
+ '.ts': 'video/mp2t',
28
+ '.mpeg': 'video/mpeg',
29
+ '.mpg': 'video/mpg'
30
+ },
31
+ 'audio': {
32
+ '.mp3': 'audio/mpeg',
33
+ '.wav': 'audio/wav',
34
+ '.flac': 'audio/flac',
35
+ '.aac': 'audio/aac',
36
+ '.ogg': 'audio/ogg',
37
+ '.m4a': 'audio/mp4',
38
+ '.opus': 'audio/opus',
39
+ },
40
+ 'document': {
41
+ '.pdf': 'application/pdf',
42
+ '.doc': 'application/msword',
43
+ '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
44
+ '.odt': 'application/vnd.oasis.opendocument.text',
45
+ '.txt': 'text/plain',
46
+ '.rtf': 'application/rtf',
47
+ '.md': 'text/markdown',
48
+ '.markdown': 'text/markdown',
49
+ '.tex': 'application/x-tex',
50
+ '.log': 'text/plain',
51
+ '.json': 'application/json',
52
+ '.xml': 'application/xml',
53
+ '.yaml': 'application/x-yaml',
54
+ '.yml': 'application/x-yaml',
55
+ '.ini': 'text/plain',
56
+ '.cfg': 'text/plain',
57
+ '.toml': 'application/toml',
58
+ '.csv': 'text/csv',
59
+ '.tsv': 'text/tab-separated-values'
60
+ },
61
+ 'presentation': {
62
+ '.ppt': 'application/vnd.ms-powerpoint',
63
+ '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
64
+ '.odp': 'application/vnd.oasis.opendocument.presentation',
65
+ },
66
+ 'spreadsheet': {
67
+ '.xls': 'application/vnd.ms-excel',
68
+ '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
69
+ '.ods': 'application/vnd.oasis.opendocument.spreadsheet',
70
+ '.csv': 'text/csv',
71
+ '.tsv': 'text/tab-separated-values'
72
+ },
73
+ 'code': {
74
+ '.py': 'text/x-python',
75
+ '.java': 'text/x-java-source',
76
+ '.c': 'text/x-c',
77
+ '.cpp': 'text/x-c++',
78
+ '.h': 'text/x-c',
79
+ '.hpp': 'text/x-c++',
80
+ '.js': 'application/javascript',
81
+ '.cjs': 'application/javascript',
82
+ '.mjs': 'application/javascript',
83
+ '.jsx': 'application/javascript',
84
+ '.ts': 'application/typescript',
85
+ '.tsx': 'application/typescript',
86
+ '.rb': 'text/x-ruby',
87
+ '.php': 'application/x-php',
88
+ '.go': 'text/x-go',
89
+ '.rs': 'text/rust',
90
+ '.swift': 'text/x-swift',
91
+ '.kt': 'text/x-kotlin',
92
+ '.sh': 'application/x-shellscript',
93
+ '.bash': 'application/x-shellscript',
94
+ '.ps1': 'application/x-powershell',
95
+ '.sql': 'application/sql',
96
+ '.yml': 'application/x-yaml',
97
+ '.coffee':'text/coffeescript',
98
+ '.lua': 'text/x-lua',
99
+ },
100
+ 'archive': {
101
+ '.zip': 'application/zip',
102
+ '.tar': 'application/x-tar',
103
+ '.gz': 'application/gzip',
104
+ '.tgz': 'application/gzip',
105
+ '.bz2': 'application/x-bzip2',
106
+ '.xz': 'application/x-xz',
107
+ '.rar': 'application/vnd.rar',
108
+ '.7z': 'application/x-7z-compressed',
109
+ '.iso': 'application/x-iso9660-image',
110
+ '.dmg': 'application/x-apple-diskimage',
111
+ '.jar': 'application/java-archive',
112
+ '.war': 'application/java-archive',
113
+ '.whl': 'application/python-wheel',
114
+ '.egg': 'application/python-egg',
115
+ },
116
+ 'font': {
117
+ '.ttf': 'font/ttf',
118
+ '.otf': 'font/otf',
119
+ '.woff': 'font/woff',
120
+ '.woff2': 'font/woff2',
121
+ '.eot': 'application/vnd.ms-fontobject'
122
+ },
123
+ 'executable': {
124
+ '.exe': 'application/vnd.microsoft.portable-executable',
125
+ '.dll': 'application/vnd.microsoft.portable-executable',
126
+ '.bin': 'application/octet-stream',
127
+ '.deb': 'application/vnd.debian.binary-package',
128
+ '.rpm': 'application/x-rpm'
129
+ }
130
+ }
131
+
132
+ # And just the sets, if you only need to test ext‐membership:
133
+ MEDIA_TYPES = make_key_map(MIME_TYPES)
134
+
@@ -1 +1,25 @@
1
- from ...list_utils import make_list
1
+ def make_list(obj:any) -> list:
2
+ """
3
+ Converts the input object to a list. If the object is already a list, it is returned as is.
4
+
5
+ Args:
6
+ obj: The object to convert.
7
+
8
+ Returns:
9
+ list: The object as a list.
10
+ """
11
+ if isinstance(obj,str):
12
+ if ',' in obj:
13
+ obj = obj.split(',')
14
+ if isinstance(obj,set) or isinstance(obj,tuple):
15
+ return list(obj)
16
+ if isinstance(obj, list):
17
+ return obj
18
+ return [obj]
19
+ def get_keys(mapping,typ=None):
20
+ typ = typ or set
21
+ if isinstance(mapping,dict):
22
+ mapping = mapping.keys()
23
+ return typ(mapping)
24
+ def make_key_map(dict_obj):
25
+ return {k:get_keys(v) for k,v in dict_obj.items()}
@@ -0,0 +1,455 @@
1
+ def is_iterable(obj:any):
2
+ try:
3
+ iterator=iter(obj)
4
+ except TypeError:
5
+ return False
6
+ else:
7
+ return True
8
+ return True
9
+
10
+ def get_type(obj:any) -> any:
11
+ """
12
+ Determines the type of the input object.
13
+
14
+ Args:
15
+ obj: The object to determine the type of.
16
+
17
+ Returns:
18
+ any: The object with the updated type.
19
+ """
20
+ if is_number(obj):
21
+ obj = int(obj)
22
+ if is_float(obj):
23
+ return float(obj)
24
+ elif obj == 'None':
25
+ obj = None
26
+ elif is_str(obj):
27
+ obj = str(obj)
28
+ return obj
29
+
30
+ def is_instance(obj:any,typ:any) -> bool:
31
+ """
32
+ Checks whether the input object can be represented as a number.
33
+
34
+ Args:
35
+ obj: The object to check.
36
+
37
+ Returns:
38
+ bool: True if the object can be represented as a number, False otherwise.
39
+ """
40
+ boolIt = False
41
+ try:
42
+ boolIt = isinstance(obj, typ)
43
+ return boolIt
44
+ except:
45
+ return boolIt
46
+
47
+ def is_number(s):
48
+ try:
49
+ float(s)
50
+ return True
51
+ except:
52
+ return False
53
+
54
+ def is_object(obj:any) -> bool:
55
+ """
56
+ Checks whether the input object is of type 'object'.
57
+
58
+ Args:
59
+ obj: The object to check.
60
+
61
+ Returns:
62
+ bool: True if the object is of type 'object', False otherwise.
63
+ """
64
+ return is_instance(obj, object)
65
+ def is_str(obj:any) -> bool:
66
+ """
67
+ Checks whether the input object is of type 'str'.
68
+
69
+ Args:
70
+ obj: The object to check.
71
+
72
+ Returns:
73
+ bool: True if the object is of type 'str', False otherwise.
74
+ """
75
+ return is_instance(obj, str)
76
+ def is_int(obj:any) -> bool:
77
+ """
78
+ Checks whether the input object is of type 'int'.
79
+
80
+ Args:
81
+ obj: The object to check.
82
+
83
+ Returns:
84
+ bool: True if the object is of type 'int', False otherwise.
85
+ """
86
+ return is_instance(obj, int)
87
+ def is_float(obj:any) -> bool:
88
+ """
89
+ Checks whether the input object is of type 'float'.
90
+
91
+ Args:
92
+ obj: The object to check.
93
+
94
+ Returns:
95
+ bool: True if the object is of type 'float', False otherwise.
96
+ """
97
+ return is_instance(obj, float)
98
+ def is_bool(obj:any) -> bool:
99
+ """
100
+ Checks whether the input object is of type 'bool'.
101
+
102
+ Args:
103
+ obj: The object to check.
104
+
105
+ Returns:
106
+ bool: True if the object is of type 'bool', False otherwise.
107
+ """
108
+ return is_instance(obj, bool)
109
+
110
+
111
+ def is_list(obj:any) -> bool:
112
+ """
113
+ Checks whether the input object is of type 'list'.
114
+
115
+ Args:
116
+ obj: The object to check.
117
+
118
+ Returns:
119
+ bool: True if the object is of type 'list', False otherwise.
120
+ """
121
+ return is_instance(obj, list)
122
+ def is_tuple(obj:any) -> bool:
123
+ """
124
+ Checks whether the input object is of type 'tuple'.
125
+
126
+ Args:
127
+ obj: The object to check.
128
+
129
+ Returns:
130
+ bool: True if the object is of type 'tuple', False otherwise.
131
+ """
132
+ return is_instance(obj, tuple)
133
+ def is_set(obj:any) -> bool:
134
+ """
135
+ Checks whether the input object is of type 'set'.
136
+
137
+ Args:
138
+ obj: The object to check.
139
+
140
+ Returns:
141
+ bool: True if the object is of type 'set', False otherwise.
142
+ """
143
+ return is_instance(obj, set)
144
+ def is_dict(obj:any) -> bool:
145
+ """
146
+ Checks whether the input object is of type 'dict'.
147
+
148
+ Args:
149
+ obj: The object to check.
150
+
151
+ Returns:
152
+ bool: True if the object is of type 'dict', False otherwise.
153
+ """
154
+ return is_instance(obj, dict)
155
+ def is_frozenset(obj:any) -> bool:
156
+ """
157
+ Checks whether the input object is of type 'frozenset'.
158
+
159
+ Args:
160
+ obj: The object to check.
161
+
162
+ Returns:
163
+ bool: True if the object is of type 'frozenset', False otherwise.
164
+ """
165
+ return is_instance(obj, frozenset)
166
+ def is_bytearray(obj:any) -> bool:
167
+ """
168
+ Checks whether the input object is of type 'bytearray'.
169
+
170
+ Args:
171
+ obj: The object to check.
172
+
173
+ Returns:
174
+ bool: True if the object is of type 'bytearray', False otherwise.
175
+ """
176
+ return is_instance(obj, bytearray)
177
+ def is_bytes(obj:any) -> bool:
178
+ """
179
+ Checks whether the input object is of type 'bytes'.
180
+
181
+ Args:
182
+ obj: The object to check.
183
+
184
+ Returns:
185
+ bool: True if the object is of type 'bytes', False otherwise.
186
+ """
187
+ return is_instance(obj, bytes)
188
+ def is_memoryview(obj:any) -> bool:
189
+ """
190
+ Checks whether the input object is of type 'memoryview'.
191
+
192
+ Args:
193
+ obj: The object to check.
194
+
195
+ Returns:
196
+ bool: True if the object is of type 'memoryview', False otherwise.
197
+ """
198
+ return is_instance(obj, memoryview)
199
+ def is_range(obj:any) -> bool:
200
+ """
201
+ Checks whether the input object is
202
+
203
+ of type 'range'.
204
+
205
+ Args:
206
+ obj: The object to check.
207
+
208
+ Returns:
209
+ bool: True if the object is of type 'range', False otherwise.
210
+ """
211
+ return is_instance(obj, range)
212
+ def is_enumerate(obj:any) -> bool:
213
+ """
214
+ Checks whether the input object is of type 'enumerate'.
215
+
216
+ Args:
217
+ obj: The object to check.
218
+
219
+ Returns:
220
+ bool: True if the object is of type 'enumerate', False otherwise.
221
+ """
222
+ return is_instance(obj, enumerate)
223
+ def is_zip(obj:any) -> bool:
224
+ """
225
+ Checks whether the input object is of type 'zip'.
226
+
227
+ Args:
228
+ obj: The object to check.
229
+
230
+ Returns:
231
+ bool: True if the object is of type 'zip', False otherwise.
232
+ """
233
+ return is_instance(obj, zip)
234
+ def is_filter(obj:any) -> bool:
235
+ """
236
+ Checks whether the input object is of type 'filter'.
237
+
238
+ Args:
239
+ obj: The object to check.
240
+
241
+ Returns:
242
+ bool: True if the object is of type 'filter', False otherwise.
243
+ """
244
+ return is_instance(obj, filter)
245
+ def is_map(obj:any) -> bool:
246
+ """
247
+ Checks whether the input object is of type 'map'.
248
+
249
+ Args:
250
+ obj: The object to check.
251
+
252
+ Returns:
253
+ bool: True if the object is of type 'map', False otherwise.
254
+ """
255
+ return is_instance(obj, map)
256
+ def is_property(obj:any) -> bool:
257
+ """
258
+ Checks whether the input object is of type 'property'.
259
+
260
+ Args:
261
+ obj: The object to check.
262
+
263
+ Returns:
264
+ bool: True if the object is of type 'property', False otherwise.
265
+ """
266
+ return is_instance(obj, property)
267
+
268
+
269
+ def is_slice(obj:any) -> bool:
270
+ """
271
+ Checks whether the input object is of type 'slice'.
272
+
273
+ Args:
274
+ obj: The object to check.
275
+
276
+ Returns:
277
+ bool: True if the object is of type 'slice', False otherwise.
278
+ """
279
+ return is_instance(obj, slice)
280
+
281
+
282
+ def is_super(obj:any) -> bool:
283
+ """
284
+ Checks whether the input object is of type 'super'.
285
+
286
+ Args:
287
+ obj: The object to check.
288
+
289
+ Returns:
290
+ bool: True if the object is of type 'super', False otherwise.
291
+ """
292
+ return is_instance(obj, super)
293
+
294
+
295
+ def is_type(obj:any) -> bool:
296
+ """
297
+ Checks whether the input object is of type 'type'.
298
+
299
+ Args:
300
+ obj: The object to check.
301
+
302
+ Returns:
303
+ bool: True if the object is of type 'type', False otherwise.
304
+ """
305
+ return is_instance(obj, type)
306
+
307
+
308
+ def is_Exception(obj:any) -> bool:
309
+ """
310
+ Checks whether the input object is of type 'Exception'.
311
+
312
+ Args:
313
+ obj: The object to check.
314
+
315
+ Returns:
316
+ bool: True if the object is of type 'Exception', False otherwise.
317
+ """
318
+ return is_instance(obj, Exception)
319
+
320
+
321
+ def is_none(obj:any) -> bool:
322
+ """
323
+ Checks whether the input object is of type 'None'.
324
+
325
+ Args:
326
+ obj: The object to check.
327
+
328
+ Returns:
329
+ bool: True if the object is of type 'None', False otherwise.
330
+ """
331
+ if type(obj) is None:
332
+ return True
333
+ else:
334
+ return False
335
+
336
+
337
+
338
+ def is_dict_or_convertable(obj:any) -> bool:
339
+ """
340
+ Checks whether the input object is of type 'dict' or can be converted to a dictionary.
341
+
342
+ Args:
343
+ obj: The object to check.
344
+
345
+ Returns:
346
+ bool: True if the object is of type 'dict' or can be converted to a dictionary, False otherwise.
347
+ """
348
+ if is_dict(obj):
349
+ return True
350
+ if is_str_convertible_dict(obj):
351
+ return True
352
+ return False
353
+ def is_str_convertible_dict(obj:any) -> bool:
354
+ """
355
+ Checks whether the input object is a string that can be converted to a dict.
356
+
357
+ Args:
358
+ obj: The object to check.
359
+
360
+ Returns:
361
+ bool: True if the object can be converted to a dict, False otherwise.
362
+ """
363
+ import json
364
+
365
+ if is_instance(obj, str):
366
+ try:
367
+ json.loads(obj)
368
+ return True
369
+ except json.JSONDecodeError:
370
+ return False
371
+
372
+ return False
373
+ def is_any_instance(value):
374
+ for each in [dict, list, int, float]:
375
+ if is_instance(value, each):
376
+ return True
377
+ def det_bool_F(obj: (tuple or list or bool) = False):
378
+ """
379
+ Determines if the given object is a boolean False value.
380
+
381
+ Args:
382
+ obj (tuple or list or bool): The object to determine the boolean False value.
383
+
384
+ Returns:
385
+ bool: True if the object is a boolean False value, False otherwise.
386
+ """
387
+ if is_instance(obj, bool):
388
+ return obj
389
+ return all(obj)
390
+ def det_bool_T(obj: (tuple or list or bool) = False):
391
+ """
392
+ Determines if the given object is a boolean True value.
393
+
394
+ Args:
395
+ obj (tuple or list or bool): The object to determine the boolean True value.
396
+
397
+ Returns:
398
+ bool: True if the object is a boolean True value, False otherwise.
399
+ """
400
+ if is_instance(obj, bool):
401
+ return obj
402
+ return any(obj)
403
+ def T_or_F_obj_eq(event: any = '', obj: any = ''):
404
+ """
405
+ Compares two objects and returns True if they are equal, False otherwise.
406
+
407
+ Args:
408
+ event (any): The first object to compare.
409
+ obj (any): The second object to compare.
410
+
411
+ Returns:
412
+ bool: True if the objects are equal, False otherwise.
413
+ """
414
+ return True if event == obj else False
415
+ def ensure_integer(page_value:any, default_value:int):
416
+ """
417
+ Ensures the given value is an integer. If not, it tries to extract
418
+ the numeric part of the value. If still unsuccessful, it defaults
419
+ to the given default value.
420
+
421
+ Parameters:
422
+ - page_value (str|int|any): The value to ensure as integer.
423
+ Non-numeric characters are stripped if necessary.
424
+ - default_value (int): The default value to return if conversion
425
+ to integer is unsuccessful.
426
+
427
+ Returns:
428
+ - int: The ensured integer value.
429
+ """
430
+ # Check if page_value is already a number
431
+ if not is_number(page_value):
432
+ # Convert to string in case it's not already
433
+ page_value = str(page_value)
434
+
435
+ # Remove non-numeric characters from the beginning
436
+ while len(page_value) > 0 and page_value[0] not in '0123456789'.split(','):
437
+ page_value = page_value[1:]
438
+
439
+ # Remove non-numeric characters from the end
440
+ while len(page_value) > 0 and page_value[-1] not in '0123456789'.split(','):
441
+ page_value = page_value[:-1]
442
+
443
+ # If page_value is empty or still not a number, use the default value
444
+ if len(page_value) == 0 or not is_number(page_value):
445
+ return default_value
446
+
447
+ # Convert page_value to an integer and return
448
+ return int(page_value)
449
+ def if_default_return_obj(obj:any,default:any=None,default_compare:any=None):
450
+ if default == default_compare:
451
+ return obj
452
+ return default
453
+
454
+
455
+