abstract-utilities 0.2.2.495__py3-none-any.whl → 0.2.2.504__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.
- abstract_utilities/__init__.py +5 -9
- abstract_utilities/class_utils/__init__.py +7 -0
- abstract_utilities/class_utils/abstract_classes.py +74 -0
- abstract_utilities/class_utils/caller_utils.py +35 -0
- abstract_utilities/class_utils/class_utils.py +109 -0
- abstract_utilities/class_utils/function_utils.py +153 -0
- abstract_utilities/class_utils/global_utils.py +56 -0
- abstract_utilities/class_utils/imports/__init__.py +2 -0
- abstract_utilities/class_utils/imports/imports.py +2 -0
- abstract_utilities/class_utils/imports/utils.py +40 -0
- abstract_utilities/class_utils/module_utils.py +63 -0
- abstract_utilities/env_utils/imports/imports.py +3 -2
- abstract_utilities/error_utils/__init__.py +2 -0
- abstract_utilities/error_utils/error_utils.py +25 -0
- abstract_utilities/error_utils/imports/__init__.py +2 -0
- abstract_utilities/error_utils/imports/imports.py +1 -0
- abstract_utilities/error_utils/imports/module_imports.py +1 -0
- abstract_utilities/file_utils/imports/imports.py +3 -18
- abstract_utilities/file_utils/imports/module_imports.py +3 -6
- abstract_utilities/file_utils/src/type_checks.py +0 -1
- abstract_utilities/hash_utils/__init__.py +2 -0
- abstract_utilities/hash_utils/hash_utils.py +5 -0
- abstract_utilities/hash_utils/imports/__init__.py +2 -0
- abstract_utilities/hash_utils/imports/imports.py +1 -0
- abstract_utilities/hash_utils/imports/module_imports.py +0 -0
- abstract_utilities/history_utils/__init__.py +2 -0
- abstract_utilities/history_utils/history_utils.py +37 -0
- abstract_utilities/history_utils/imports/__init__.py +2 -0
- abstract_utilities/history_utils/imports/imports.py +1 -0
- abstract_utilities/history_utils/imports/module_imports.py +0 -0
- abstract_utilities/import_utils/imports/imports.py +1 -1
- abstract_utilities/import_utils/imports/module_imports.py +1 -1
- abstract_utilities/import_utils/src/__init__.py +1 -1
- abstract_utilities/import_utils/src/clean_imports.py +31 -5
- abstract_utilities/import_utils/src/dot_utils.py +9 -0
- abstract_utilities/import_utils/src/package_utilss/__init__.py +139 -0
- abstract_utilities/import_utils/src/package_utilss/context_utils.py +27 -0
- abstract_utilities/import_utils/src/package_utilss/import_collectors.py +53 -0
- abstract_utilities/import_utils/src/package_utilss/path_utils.py +28 -0
- abstract_utilities/import_utils/src/package_utilss/safe_import.py +27 -0
- abstract_utilities/import_utils/src/pkg_utils.py +140 -0
- abstract_utilities/imports.py +18 -0
- abstract_utilities/json_utils/__init__.py +2 -0
- abstract_utilities/json_utils/imports/__init__.py +2 -0
- abstract_utilities/json_utils/imports/imports.py +2 -0
- abstract_utilities/json_utils/imports/module_imports.py +5 -0
- abstract_utilities/json_utils/json_utils.py +743 -0
- abstract_utilities/list_utils/__init__.py +2 -0
- abstract_utilities/list_utils/imports/__init__.py +2 -0
- abstract_utilities/list_utils/imports/imports.py +1 -0
- abstract_utilities/list_utils/imports/module_imports.py +0 -0
- abstract_utilities/list_utils/list_utils.py +199 -0
- abstract_utilities/log_utils/__init__.py +5 -0
- abstract_utilities/log_utils/abstractLogManager.py +64 -0
- abstract_utilities/log_utils/call_response.py +68 -0
- abstract_utilities/log_utils/imports/__init__.py +2 -0
- abstract_utilities/log_utils/imports/imports.py +7 -0
- abstract_utilities/log_utils/imports/module_imports.py +2 -0
- abstract_utilities/log_utils/log_file.py +56 -0
- abstract_utilities/log_utils/logger_callable.py +49 -0
- abstract_utilities/math_utils/__init__.py +2 -0
- abstract_utilities/math_utils/imports/__init__.py +2 -0
- abstract_utilities/math_utils/imports/imports.py +2 -0
- abstract_utilities/math_utils/imports/module_imports.py +1 -0
- abstract_utilities/math_utils/math_utils.py +208 -0
- abstract_utilities/parse_utils/__init__.py +2 -0
- abstract_utilities/parse_utils/imports/__init__.py +3 -0
- abstract_utilities/parse_utils/imports/constants.py +10 -0
- abstract_utilities/parse_utils/imports/imports.py +2 -0
- abstract_utilities/parse_utils/imports/module_imports.py +4 -0
- abstract_utilities/parse_utils/parse_utils.py +516 -0
- abstract_utilities/path_utils/__init__.py +2 -0
- abstract_utilities/path_utils/imports/__init__.py +2 -0
- abstract_utilities/path_utils/imports/imports.py +1 -0
- abstract_utilities/path_utils/imports/module_imports.py +6 -0
- abstract_utilities/path_utils/path_utils.py +715 -0
- abstract_utilities/path_utils.py +94 -2
- abstract_utilities/read_write_utils/__init__.py +1 -0
- abstract_utilities/read_write_utils/imports/__init__.py +2 -0
- abstract_utilities/read_write_utils/imports/imports.py +2 -0
- abstract_utilities/read_write_utils/imports/module_imports.py +5 -0
- abstract_utilities/read_write_utils/read_write_utils.py +338 -0
- abstract_utilities/read_write_utils.py +2 -4
- abstract_utilities/safe_utils/__init__.py +2 -0
- abstract_utilities/safe_utils/imports/__init__.py +3 -0
- abstract_utilities/safe_utils/imports/imports.py +1 -0
- abstract_utilities/safe_utils/imports/module_imports.py +2 -0
- abstract_utilities/safe_utils/safe_utils.py +130 -0
- abstract_utilities/ssh_utils/__init__.py +2 -1
- abstract_utilities/ssh_utils/classes.py +0 -1
- abstract_utilities/ssh_utils/cmd_utils.py +207 -0
- abstract_utilities/ssh_utils/imports/__init__.py +3 -0
- abstract_utilities/ssh_utils/imports/imports.py +5 -0
- abstract_utilities/ssh_utils/imports/module_imports.py +5 -0
- abstract_utilities/ssh_utils/imports/utils.py +189 -0
- abstract_utilities/ssh_utils/pexpect_utils.py +11 -18
- abstract_utilities/string_utils/__init__.py +4 -0
- abstract_utilities/string_utils/clean_utils.py +28 -0
- abstract_utilities/string_utils/eat_utils.py +103 -0
- abstract_utilities/string_utils/imports/__init__.py +3 -0
- abstract_utilities/string_utils/imports/imports.py +2 -0
- abstract_utilities/string_utils/imports/module_imports.py +2 -0
- abstract_utilities/string_utils/imports/utils.py +81 -0
- abstract_utilities/string_utils/replace_utils.py +27 -0
- abstract_utilities/thread_utils/__init__.py +2 -0
- abstract_utilities/thread_utils/imports/__init__.py +2 -0
- abstract_utilities/thread_utils/imports/imports.py +2 -0
- abstract_utilities/thread_utils/imports/module_imports.py +2 -0
- abstract_utilities/thread_utils/thread_utils.py +140 -0
- abstract_utilities/time_utils/__init__.py +2 -0
- abstract_utilities/time_utils/imports/__init__.py +2 -0
- abstract_utilities/time_utils/imports/imports.py +3 -0
- abstract_utilities/time_utils/imports/module_imports.py +1 -0
- abstract_utilities/time_utils/time_utils.py +392 -0
- abstract_utilities/type_utils/__init__.py +3 -0
- abstract_utilities/type_utils/alpha_utils.py +59 -0
- abstract_utilities/type_utils/imports/__init__.py +2 -0
- abstract_utilities/type_utils/imports/imports.py +4 -0
- abstract_utilities/type_utils/imports/module_imports.py +1 -0
- abstract_utilities/type_utils/num_utils.py +19 -0
- abstract_utilities/type_utils/type_utils.py +981 -0
- {abstract_utilities-0.2.2.495.dist-info → abstract_utilities-0.2.2.504.dist-info}/METADATA +1 -1
- abstract_utilities-0.2.2.504.dist-info/RECORD +229 -0
- abstract_utilities-0.2.2.495.dist-info/RECORD +0 -123
- {abstract_utilities-0.2.2.495.dist-info → abstract_utilities-0.2.2.504.dist-info}/WHEEL +0 -0
- {abstract_utilities-0.2.2.495.dist-info → abstract_utilities-0.2.2.504.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,981 @@
|
|
|
1
|
+
"""
|
|
2
|
+
type_utils.py
|
|
3
|
+
|
|
4
|
+
This module provides a collection of utility functions for type checking and conversion.
|
|
5
|
+
It includes functions to determine the type of an object, check if an object is a specific type,
|
|
6
|
+
and perform type conversions. These functions help simplify the process of handling different
|
|
7
|
+
types of data and ensure consistent behavior across different data types.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
import abstract_utilities.type_utils as type_utils
|
|
11
|
+
|
|
12
|
+
Functions:
|
|
13
|
+
- is_iterable(obj: any) -> bool
|
|
14
|
+
- is_number(obj: any) -> bool
|
|
15
|
+
- is_str(obj: any) -> bool
|
|
16
|
+
- is_int(obj: any) -> bool
|
|
17
|
+
- is_float(obj: any) -> bool
|
|
18
|
+
- is_bool(obj: any) -> bool
|
|
19
|
+
- is_list(obj: any) -> bool
|
|
20
|
+
- is_tuple(obj: any) -> bool
|
|
21
|
+
- is_set(obj: any) -> bool
|
|
22
|
+
- is_dict(obj: any) -> bool
|
|
23
|
+
- is_frozenset(obj: any) -> bool
|
|
24
|
+
- is_bytearray(obj: any) -> bool
|
|
25
|
+
- is_bytes(obj: any) -> bool
|
|
26
|
+
- is_memoryview(obj: any) -> bool
|
|
27
|
+
- is_range(obj: any) -> bool
|
|
28
|
+
- is_enumerate(obj: any) -> bool
|
|
29
|
+
- is_zip(obj: any) -> bool
|
|
30
|
+
- is_filter(obj: any) -> bool
|
|
31
|
+
- is_map(obj: any) -> bool
|
|
32
|
+
- is_property(obj: any) -> bool
|
|
33
|
+
- is_slice(obj: any) -> bool
|
|
34
|
+
- is_super(obj: any) -> bool
|
|
35
|
+
- is_type(obj: any) -> bool
|
|
36
|
+
- is_Exception(obj: any) -> bool
|
|
37
|
+
- is_none(obj: any) -> bool
|
|
38
|
+
- is_str_convertible_dict(obj: any) -> bool
|
|
39
|
+
- is_dict_or_convertable(obj: any) -> bool
|
|
40
|
+
- dict_check_conversion(obj: any) -> Union[dict, any]
|
|
41
|
+
- make_list(obj: any) -> list
|
|
42
|
+
- make_list_lower(ls: list) -> list
|
|
43
|
+
- make_float(obj: Union[str, float, int]) -> float
|
|
44
|
+
- make_bool(obj: Union[bool, int, str]) -> Union[bool, str]
|
|
45
|
+
- make_str(obj: any) -> str
|
|
46
|
+
- get_obj_obj(obj_type: str, obj: any) -> any
|
|
47
|
+
- get_len_or_num(obj: any) -> int
|
|
48
|
+
- get_types_list() -> list
|
|
49
|
+
- det_bool_F(obj: (tuple or list or bool) = False) -> bool
|
|
50
|
+
- det_bool_T(obj: (tuple or list or bool) = False) -> bool
|
|
51
|
+
- T_or_F_obj_eq(event: any = '', obj: any = '') -> bool
|
|
52
|
+
|
|
53
|
+
This module is part of the `abstract_utilities` package.
|
|
54
|
+
|
|
55
|
+
Author: putkoff
|
|
56
|
+
Date: 05/31/2023
|
|
57
|
+
Version: 0.1.2
|
|
58
|
+
"""
|
|
59
|
+
from .imports import *
|
|
60
|
+
from .alpha_utils import *
|
|
61
|
+
from .num_utils import *
|
|
62
|
+
# A big, but by no means exhaustive, map of extensions to mime‐types by category:
|
|
63
|
+
MIME_TYPES = {
|
|
64
|
+
'image': {
|
|
65
|
+
'.jpg': 'image/jpeg',
|
|
66
|
+
'.jpeg': 'image/jpeg',
|
|
67
|
+
'.png': 'image/png',
|
|
68
|
+
'.gif': 'image/gif',
|
|
69
|
+
'.bmp': 'image/bmp',
|
|
70
|
+
'.tiff': 'image/tiff',
|
|
71
|
+
'.webp': 'image/webp',
|
|
72
|
+
'.svg': 'image/svg+xml',
|
|
73
|
+
'.ico': 'image/vnd.microsoft.icon',
|
|
74
|
+
'.heic': 'image/heic',
|
|
75
|
+
'.psd': 'image/vnd.adobe.photoshop',
|
|
76
|
+
'.raw': 'image/x-raw',
|
|
77
|
+
},
|
|
78
|
+
'video': {
|
|
79
|
+
'.mp4': 'video/mp4',
|
|
80
|
+
'.webm': 'video/webm',
|
|
81
|
+
'.ogg': 'video/ogg',
|
|
82
|
+
'.mov': 'video/quicktime',
|
|
83
|
+
'.avi': 'video/x-msvideo',
|
|
84
|
+
'.mkv': 'video/x-matroska',
|
|
85
|
+
'.flv': 'video/x-flv',
|
|
86
|
+
'.wmv': 'video/x-ms-wmv',
|
|
87
|
+
'.3gp': 'video/3gpp',
|
|
88
|
+
'.ts': 'video/mp2t',
|
|
89
|
+
'.mpeg': 'video/mpeg',
|
|
90
|
+
'.mpg': 'video/mpg'
|
|
91
|
+
},
|
|
92
|
+
'audio': {
|
|
93
|
+
'.mp3': 'audio/mpeg',
|
|
94
|
+
'.wav': 'audio/wav',
|
|
95
|
+
'.flac': 'audio/flac',
|
|
96
|
+
'.aac': 'audio/aac',
|
|
97
|
+
'.ogg': 'audio/ogg',
|
|
98
|
+
'.m4a': 'audio/mp4',
|
|
99
|
+
'.opus': 'audio/opus',
|
|
100
|
+
},
|
|
101
|
+
'document': {
|
|
102
|
+
'.pdf': 'application/pdf',
|
|
103
|
+
'.doc': 'application/msword',
|
|
104
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
105
|
+
'.odt': 'application/vnd.oasis.opendocument.text',
|
|
106
|
+
'.txt': 'text/plain',
|
|
107
|
+
'.rtf': 'application/rtf',
|
|
108
|
+
'.md': 'text/markdown',
|
|
109
|
+
'.markdown': 'text/markdown',
|
|
110
|
+
'.tex': 'application/x-tex',
|
|
111
|
+
'.log': 'text/plain',
|
|
112
|
+
'.json': 'application/json',
|
|
113
|
+
'.xml': 'application/xml',
|
|
114
|
+
'.yaml': 'application/x-yaml',
|
|
115
|
+
'.yml': 'application/x-yaml',
|
|
116
|
+
'.ini': 'text/plain',
|
|
117
|
+
'.cfg': 'text/plain',
|
|
118
|
+
'.toml': 'application/toml',
|
|
119
|
+
'.csv': 'text/csv',
|
|
120
|
+
'.tsv': 'text/tab-separated-values'
|
|
121
|
+
},
|
|
122
|
+
'presentation': {
|
|
123
|
+
'.ppt': 'application/vnd.ms-powerpoint',
|
|
124
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
125
|
+
'.odp': 'application/vnd.oasis.opendocument.presentation',
|
|
126
|
+
},
|
|
127
|
+
'spreadsheet': {
|
|
128
|
+
'.xls': 'application/vnd.ms-excel',
|
|
129
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
130
|
+
'.ods': 'application/vnd.oasis.opendocument.spreadsheet',
|
|
131
|
+
'.csv': 'text/csv',
|
|
132
|
+
'.tsv': 'text/tab-separated-values'
|
|
133
|
+
},
|
|
134
|
+
'code': {
|
|
135
|
+
'.py': 'text/x-python',
|
|
136
|
+
'.java': 'text/x-java-source',
|
|
137
|
+
'.c': 'text/x-c',
|
|
138
|
+
'.cpp': 'text/x-c++',
|
|
139
|
+
'.h': 'text/x-c',
|
|
140
|
+
'.hpp': 'text/x-c++',
|
|
141
|
+
'.js': 'application/javascript',
|
|
142
|
+
'.cjs': 'application/javascript',
|
|
143
|
+
'.mjs': 'application/javascript',
|
|
144
|
+
'.jsx': 'application/javascript',
|
|
145
|
+
'.ts': 'application/typescript',
|
|
146
|
+
'.tsx': 'application/typescript',
|
|
147
|
+
'.rb': 'text/x-ruby',
|
|
148
|
+
'.php': 'application/x-php',
|
|
149
|
+
'.go': 'text/x-go',
|
|
150
|
+
'.rs': 'text/rust',
|
|
151
|
+
'.swift': 'text/x-swift',
|
|
152
|
+
'.kt': 'text/x-kotlin',
|
|
153
|
+
'.sh': 'application/x-shellscript',
|
|
154
|
+
'.bash': 'application/x-shellscript',
|
|
155
|
+
'.ps1': 'application/x-powershell',
|
|
156
|
+
'.sql': 'application/sql',
|
|
157
|
+
'.yml': 'application/x-yaml',
|
|
158
|
+
'.coffee':'text/coffeescript',
|
|
159
|
+
'.lua': 'text/x-lua',
|
|
160
|
+
},
|
|
161
|
+
'archive': {
|
|
162
|
+
'.zip': 'application/zip',
|
|
163
|
+
'.tar': 'application/x-tar',
|
|
164
|
+
'.gz': 'application/gzip',
|
|
165
|
+
'.tgz': 'application/gzip',
|
|
166
|
+
'.bz2': 'application/x-bzip2',
|
|
167
|
+
'.xz': 'application/x-xz',
|
|
168
|
+
'.rar': 'application/vnd.rar',
|
|
169
|
+
'.7z': 'application/x-7z-compressed',
|
|
170
|
+
'.iso': 'application/x-iso9660-image',
|
|
171
|
+
'.dmg': 'application/x-apple-diskimage',
|
|
172
|
+
'.jar': 'application/java-archive',
|
|
173
|
+
'.war': 'application/java-archive',
|
|
174
|
+
'.whl': 'application/python-wheel',
|
|
175
|
+
'.egg': 'application/python-egg',
|
|
176
|
+
},
|
|
177
|
+
'font': {
|
|
178
|
+
'.ttf': 'font/ttf',
|
|
179
|
+
'.otf': 'font/otf',
|
|
180
|
+
'.woff': 'font/woff',
|
|
181
|
+
'.woff2': 'font/woff2',
|
|
182
|
+
'.eot': 'application/vnd.ms-fontobject'
|
|
183
|
+
},
|
|
184
|
+
'executable': {
|
|
185
|
+
'.exe': 'application/vnd.microsoft.portable-executable',
|
|
186
|
+
'.dll': 'application/vnd.microsoft.portable-executable',
|
|
187
|
+
'.bin': 'application/octet-stream',
|
|
188
|
+
'.deb': 'application/vnd.debian.binary-package',
|
|
189
|
+
'.rpm': 'application/x-rpm'
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# And just the sets, if you only need to test ext‐membership:
|
|
194
|
+
MEDIA_TYPES = {
|
|
195
|
+
category: set(mapping.keys())
|
|
196
|
+
for category, mapping in MIME_TYPES.items()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def get_media_map(categories=None):
|
|
201
|
+
"""
|
|
202
|
+
Return a sub‐dict of MEDIA_TYPES for the given categories.
|
|
203
|
+
If categories is None or empty, return the whole MEDIA_TYPES.
|
|
204
|
+
"""
|
|
205
|
+
if not categories:
|
|
206
|
+
return MEDIA_TYPES
|
|
207
|
+
cats = {str(c) for c in categories}
|
|
208
|
+
return {c: MEDIA_TYPES[c] for c in cats if c in MEDIA_TYPES}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def get_media_exts(categories=None):
|
|
212
|
+
"""
|
|
213
|
+
Return a flat, sorted list of all extensions for the given categories.
|
|
214
|
+
"""
|
|
215
|
+
media_map = get_media_map(categories)
|
|
216
|
+
return sorted({ext for exts in media_map.values() for ext in exts})
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def confirm_type(path_or_ext, categories=None,**kwargs):
|
|
220
|
+
"""
|
|
221
|
+
Given a file‐path or extension, return its media category (e.g. "image"), or None.
|
|
222
|
+
"""
|
|
223
|
+
categories = categories or kwargs.get('media_types')
|
|
224
|
+
ext = Path(path_or_ext).suffix.lower()
|
|
225
|
+
media_map = get_media_map(categories)
|
|
226
|
+
for category, exts in media_map.items():
|
|
227
|
+
if ext in exts:
|
|
228
|
+
return category
|
|
229
|
+
return None
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def is_media_type(path_or_ext, categories=None,**kwargs):
|
|
233
|
+
"""
|
|
234
|
+
True if the given file‐path or extension belongs to one of the categories.
|
|
235
|
+
"""
|
|
236
|
+
categories = categories or kwargs.get('media_types')
|
|
237
|
+
return confirm_type(path_or_ext, categories) is not None
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def get_mime_type(path_or_ext):
|
|
241
|
+
"""
|
|
242
|
+
Look up the MIME type by extension in MIME_TYPES; fall back to octet‐stream.
|
|
243
|
+
"""
|
|
244
|
+
ext = Path(path_or_ext).suffix.lower()
|
|
245
|
+
for mapping in MIME_TYPES.values():
|
|
246
|
+
if ext in mapping:
|
|
247
|
+
return mapping[ext]
|
|
248
|
+
return 'application/octet-stream'
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def get_all_file_types(categories=None, directory=None,**kwargs):
|
|
252
|
+
"""
|
|
253
|
+
Recursively glob for files under `directory` whose extension belongs to `categories`.
|
|
254
|
+
Returns a list of full paths.
|
|
255
|
+
"""
|
|
256
|
+
categories = categories or kwargs.get('media_types')
|
|
257
|
+
base = Path(directory)
|
|
258
|
+
if not base.is_dir():
|
|
259
|
+
return []
|
|
260
|
+
wanted = get_media_map(categories)
|
|
261
|
+
return [
|
|
262
|
+
str(p)
|
|
263
|
+
for p in base.rglob('*')
|
|
264
|
+
if p.is_file() and Path(p).suffix.lower() in {e for exts in wanted.values() for e in exts}
|
|
265
|
+
]
|
|
266
|
+
|
|
267
|
+
def is_iterable(obj:any):
|
|
268
|
+
try:
|
|
269
|
+
iterator=iter(obj)
|
|
270
|
+
except TypeError:
|
|
271
|
+
return False
|
|
272
|
+
else:
|
|
273
|
+
return True
|
|
274
|
+
return True
|
|
275
|
+
|
|
276
|
+
def get_type(obj:any) -> any:
|
|
277
|
+
"""
|
|
278
|
+
Determines the type of the input object.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
obj: The object to determine the type of.
|
|
282
|
+
|
|
283
|
+
Returns:
|
|
284
|
+
any: The object with the updated type.
|
|
285
|
+
"""
|
|
286
|
+
if is_number(obj):
|
|
287
|
+
obj = int(obj)
|
|
288
|
+
if is_float(obj):
|
|
289
|
+
return float(obj)
|
|
290
|
+
elif obj == 'None':
|
|
291
|
+
obj = None
|
|
292
|
+
elif is_str(obj):
|
|
293
|
+
obj = str(obj)
|
|
294
|
+
return obj
|
|
295
|
+
|
|
296
|
+
def is_instance(obj:any,typ:any) -> bool:
|
|
297
|
+
"""
|
|
298
|
+
Checks whether the input object can be represented as a number.
|
|
299
|
+
|
|
300
|
+
Args:
|
|
301
|
+
obj: The object to check.
|
|
302
|
+
|
|
303
|
+
Returns:
|
|
304
|
+
bool: True if the object can be represented as a number, False otherwise.
|
|
305
|
+
"""
|
|
306
|
+
boolIt = False
|
|
307
|
+
try:
|
|
308
|
+
boolIt = isinstance(obj, typ)
|
|
309
|
+
return boolIt
|
|
310
|
+
except:
|
|
311
|
+
return boolIt
|
|
312
|
+
|
|
313
|
+
def is_number(s):
|
|
314
|
+
try:
|
|
315
|
+
float(s)
|
|
316
|
+
return True
|
|
317
|
+
except:
|
|
318
|
+
return False
|
|
319
|
+
|
|
320
|
+
def is_object(obj:any) -> bool:
|
|
321
|
+
"""
|
|
322
|
+
Checks whether the input object is of type 'object'.
|
|
323
|
+
|
|
324
|
+
Args:
|
|
325
|
+
obj: The object to check.
|
|
326
|
+
|
|
327
|
+
Returns:
|
|
328
|
+
bool: True if the object is of type 'object', False otherwise.
|
|
329
|
+
"""
|
|
330
|
+
return is_instance(obj, object)
|
|
331
|
+
def is_str(obj:any) -> bool:
|
|
332
|
+
"""
|
|
333
|
+
Checks whether the input object is of type 'str'.
|
|
334
|
+
|
|
335
|
+
Args:
|
|
336
|
+
obj: The object to check.
|
|
337
|
+
|
|
338
|
+
Returns:
|
|
339
|
+
bool: True if the object is of type 'str', False otherwise.
|
|
340
|
+
"""
|
|
341
|
+
return is_instance(obj, str)
|
|
342
|
+
def is_int(obj:any) -> bool:
|
|
343
|
+
"""
|
|
344
|
+
Checks whether the input object is of type 'int'.
|
|
345
|
+
|
|
346
|
+
Args:
|
|
347
|
+
obj: The object to check.
|
|
348
|
+
|
|
349
|
+
Returns:
|
|
350
|
+
bool: True if the object is of type 'int', False otherwise.
|
|
351
|
+
"""
|
|
352
|
+
return is_instance(obj, int)
|
|
353
|
+
def is_float(obj:any) -> bool:
|
|
354
|
+
"""
|
|
355
|
+
Checks whether the input object is of type 'float'.
|
|
356
|
+
|
|
357
|
+
Args:
|
|
358
|
+
obj: The object to check.
|
|
359
|
+
|
|
360
|
+
Returns:
|
|
361
|
+
bool: True if the object is of type 'float', False otherwise.
|
|
362
|
+
"""
|
|
363
|
+
return is_instance(obj, float)
|
|
364
|
+
def is_bool(obj:any) -> bool:
|
|
365
|
+
"""
|
|
366
|
+
Checks whether the input object is of type 'bool'.
|
|
367
|
+
|
|
368
|
+
Args:
|
|
369
|
+
obj: The object to check.
|
|
370
|
+
|
|
371
|
+
Returns:
|
|
372
|
+
bool: True if the object is of type 'bool', False otherwise.
|
|
373
|
+
"""
|
|
374
|
+
return is_instance(obj, bool)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def is_list(obj:any) -> bool:
|
|
378
|
+
"""
|
|
379
|
+
Checks whether the input object is of type 'list'.
|
|
380
|
+
|
|
381
|
+
Args:
|
|
382
|
+
obj: The object to check.
|
|
383
|
+
|
|
384
|
+
Returns:
|
|
385
|
+
bool: True if the object is of type 'list', False otherwise.
|
|
386
|
+
"""
|
|
387
|
+
return is_instance(obj, list)
|
|
388
|
+
def is_tuple(obj:any) -> bool:
|
|
389
|
+
"""
|
|
390
|
+
Checks whether the input object is of type 'tuple'.
|
|
391
|
+
|
|
392
|
+
Args:
|
|
393
|
+
obj: The object to check.
|
|
394
|
+
|
|
395
|
+
Returns:
|
|
396
|
+
bool: True if the object is of type 'tuple', False otherwise.
|
|
397
|
+
"""
|
|
398
|
+
return is_instance(obj, tuple)
|
|
399
|
+
def is_set(obj:any) -> bool:
|
|
400
|
+
"""
|
|
401
|
+
Checks whether the input object is of type 'set'.
|
|
402
|
+
|
|
403
|
+
Args:
|
|
404
|
+
obj: The object to check.
|
|
405
|
+
|
|
406
|
+
Returns:
|
|
407
|
+
bool: True if the object is of type 'set', False otherwise.
|
|
408
|
+
"""
|
|
409
|
+
return is_instance(obj, set)
|
|
410
|
+
def is_dict(obj:any) -> bool:
|
|
411
|
+
"""
|
|
412
|
+
Checks whether the input object is of type 'dict'.
|
|
413
|
+
|
|
414
|
+
Args:
|
|
415
|
+
obj: The object to check.
|
|
416
|
+
|
|
417
|
+
Returns:
|
|
418
|
+
bool: True if the object is of type 'dict', False otherwise.
|
|
419
|
+
"""
|
|
420
|
+
return is_instance(obj, dict)
|
|
421
|
+
def is_frozenset(obj:any) -> bool:
|
|
422
|
+
"""
|
|
423
|
+
Checks whether the input object is of type 'frozenset'.
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
obj: The object to check.
|
|
427
|
+
|
|
428
|
+
Returns:
|
|
429
|
+
bool: True if the object is of type 'frozenset', False otherwise.
|
|
430
|
+
"""
|
|
431
|
+
return is_instance(obj, frozenset)
|
|
432
|
+
def is_bytearray(obj:any) -> bool:
|
|
433
|
+
"""
|
|
434
|
+
Checks whether the input object is of type 'bytearray'.
|
|
435
|
+
|
|
436
|
+
Args:
|
|
437
|
+
obj: The object to check.
|
|
438
|
+
|
|
439
|
+
Returns:
|
|
440
|
+
bool: True if the object is of type 'bytearray', False otherwise.
|
|
441
|
+
"""
|
|
442
|
+
return is_instance(obj, bytearray)
|
|
443
|
+
def is_bytes(obj:any) -> bool:
|
|
444
|
+
"""
|
|
445
|
+
Checks whether the input object is of type 'bytes'.
|
|
446
|
+
|
|
447
|
+
Args:
|
|
448
|
+
obj: The object to check.
|
|
449
|
+
|
|
450
|
+
Returns:
|
|
451
|
+
bool: True if the object is of type 'bytes', False otherwise.
|
|
452
|
+
"""
|
|
453
|
+
return is_instance(obj, bytes)
|
|
454
|
+
def is_memoryview(obj:any) -> bool:
|
|
455
|
+
"""
|
|
456
|
+
Checks whether the input object is of type 'memoryview'.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
obj: The object to check.
|
|
460
|
+
|
|
461
|
+
Returns:
|
|
462
|
+
bool: True if the object is of type 'memoryview', False otherwise.
|
|
463
|
+
"""
|
|
464
|
+
return is_instance(obj, memoryview)
|
|
465
|
+
def is_range(obj:any) -> bool:
|
|
466
|
+
"""
|
|
467
|
+
Checks whether the input object is
|
|
468
|
+
|
|
469
|
+
of type 'range'.
|
|
470
|
+
|
|
471
|
+
Args:
|
|
472
|
+
obj: The object to check.
|
|
473
|
+
|
|
474
|
+
Returns:
|
|
475
|
+
bool: True if the object is of type 'range', False otherwise.
|
|
476
|
+
"""
|
|
477
|
+
return is_instance(obj, range)
|
|
478
|
+
def is_enumerate(obj:any) -> bool:
|
|
479
|
+
"""
|
|
480
|
+
Checks whether the input object is of type 'enumerate'.
|
|
481
|
+
|
|
482
|
+
Args:
|
|
483
|
+
obj: The object to check.
|
|
484
|
+
|
|
485
|
+
Returns:
|
|
486
|
+
bool: True if the object is of type 'enumerate', False otherwise.
|
|
487
|
+
"""
|
|
488
|
+
return is_instance(obj, enumerate)
|
|
489
|
+
def is_zip(obj:any) -> bool:
|
|
490
|
+
"""
|
|
491
|
+
Checks whether the input object is of type 'zip'.
|
|
492
|
+
|
|
493
|
+
Args:
|
|
494
|
+
obj: The object to check.
|
|
495
|
+
|
|
496
|
+
Returns:
|
|
497
|
+
bool: True if the object is of type 'zip', False otherwise.
|
|
498
|
+
"""
|
|
499
|
+
return is_instance(obj, zip)
|
|
500
|
+
def is_filter(obj:any) -> bool:
|
|
501
|
+
"""
|
|
502
|
+
Checks whether the input object is of type 'filter'.
|
|
503
|
+
|
|
504
|
+
Args:
|
|
505
|
+
obj: The object to check.
|
|
506
|
+
|
|
507
|
+
Returns:
|
|
508
|
+
bool: True if the object is of type 'filter', False otherwise.
|
|
509
|
+
"""
|
|
510
|
+
return is_instance(obj, filter)
|
|
511
|
+
def is_map(obj:any) -> bool:
|
|
512
|
+
"""
|
|
513
|
+
Checks whether the input object is of type 'map'.
|
|
514
|
+
|
|
515
|
+
Args:
|
|
516
|
+
obj: The object to check.
|
|
517
|
+
|
|
518
|
+
Returns:
|
|
519
|
+
bool: True if the object is of type 'map', False otherwise.
|
|
520
|
+
"""
|
|
521
|
+
return is_instance(obj, map)
|
|
522
|
+
def is_property(obj:any) -> bool:
|
|
523
|
+
"""
|
|
524
|
+
Checks whether the input object is of type 'property'.
|
|
525
|
+
|
|
526
|
+
Args:
|
|
527
|
+
obj: The object to check.
|
|
528
|
+
|
|
529
|
+
Returns:
|
|
530
|
+
bool: True if the object is of type 'property', False otherwise.
|
|
531
|
+
"""
|
|
532
|
+
return is_instance(obj, property)
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
def is_slice(obj:any) -> bool:
|
|
536
|
+
"""
|
|
537
|
+
Checks whether the input object is of type 'slice'.
|
|
538
|
+
|
|
539
|
+
Args:
|
|
540
|
+
obj: The object to check.
|
|
541
|
+
|
|
542
|
+
Returns:
|
|
543
|
+
bool: True if the object is of type 'slice', False otherwise.
|
|
544
|
+
"""
|
|
545
|
+
return is_instance(obj, slice)
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
def is_super(obj:any) -> bool:
|
|
549
|
+
"""
|
|
550
|
+
Checks whether the input object is of type 'super'.
|
|
551
|
+
|
|
552
|
+
Args:
|
|
553
|
+
obj: The object to check.
|
|
554
|
+
|
|
555
|
+
Returns:
|
|
556
|
+
bool: True if the object is of type 'super', False otherwise.
|
|
557
|
+
"""
|
|
558
|
+
return is_instance(obj, super)
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def is_type(obj:any) -> bool:
|
|
562
|
+
"""
|
|
563
|
+
Checks whether the input object is of type 'type'.
|
|
564
|
+
|
|
565
|
+
Args:
|
|
566
|
+
obj: The object to check.
|
|
567
|
+
|
|
568
|
+
Returns:
|
|
569
|
+
bool: True if the object is of type 'type', False otherwise.
|
|
570
|
+
"""
|
|
571
|
+
return is_instance(obj, type)
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
def is_Exception(obj:any) -> bool:
|
|
575
|
+
"""
|
|
576
|
+
Checks whether the input object is of type 'Exception'.
|
|
577
|
+
|
|
578
|
+
Args:
|
|
579
|
+
obj: The object to check.
|
|
580
|
+
|
|
581
|
+
Returns:
|
|
582
|
+
bool: True if the object is of type 'Exception', False otherwise.
|
|
583
|
+
"""
|
|
584
|
+
return is_instance(obj, Exception)
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
def is_none(obj:any) -> bool:
|
|
588
|
+
"""
|
|
589
|
+
Checks whether the input object is of type 'None'.
|
|
590
|
+
|
|
591
|
+
Args:
|
|
592
|
+
obj: The object to check.
|
|
593
|
+
|
|
594
|
+
Returns:
|
|
595
|
+
bool: True if the object is of type 'None', False otherwise.
|
|
596
|
+
"""
|
|
597
|
+
if type(obj) is None:
|
|
598
|
+
return True
|
|
599
|
+
else:
|
|
600
|
+
return False
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def is_dict_or_convertable(obj:any) -> bool:
|
|
605
|
+
"""
|
|
606
|
+
Checks whether the input object is of type 'dict' or can be converted to a dictionary.
|
|
607
|
+
|
|
608
|
+
Args:
|
|
609
|
+
obj: The object to check.
|
|
610
|
+
|
|
611
|
+
Returns:
|
|
612
|
+
bool: True if the object is of type 'dict' or can be converted to a dictionary, False otherwise.
|
|
613
|
+
"""
|
|
614
|
+
if is_dict(obj):
|
|
615
|
+
return True
|
|
616
|
+
if is_str_convertible_dict(obj):
|
|
617
|
+
return True
|
|
618
|
+
return False
|
|
619
|
+
def is_str_convertible_dict(obj:any) -> bool:
|
|
620
|
+
"""
|
|
621
|
+
Checks whether the input object is a string that can be converted to a dict.
|
|
622
|
+
|
|
623
|
+
Args:
|
|
624
|
+
obj: The object to check.
|
|
625
|
+
|
|
626
|
+
Returns:
|
|
627
|
+
bool: True if the object can be converted to a dict, False otherwise.
|
|
628
|
+
"""
|
|
629
|
+
import json
|
|
630
|
+
|
|
631
|
+
if is_instance(obj, str):
|
|
632
|
+
try:
|
|
633
|
+
json.loads(obj)
|
|
634
|
+
return True
|
|
635
|
+
except json.JSONDecodeError:
|
|
636
|
+
return False
|
|
637
|
+
|
|
638
|
+
return False
|
|
639
|
+
|
|
640
|
+
def dict_check_conversion(obj:any) -> Union[dict,any]:
|
|
641
|
+
"""
|
|
642
|
+
Converts the input object to a dictionary if possible.
|
|
643
|
+
|
|
644
|
+
Args:
|
|
645
|
+
obj: The object to convert.
|
|
646
|
+
|
|
647
|
+
Returns:
|
|
648
|
+
The object converted to a dictionary if possible, otherwise the original object.
|
|
649
|
+
"""
|
|
650
|
+
import json
|
|
651
|
+
|
|
652
|
+
if is_dict_or_convertable(obj):
|
|
653
|
+
if is_dict(obj):
|
|
654
|
+
return obj
|
|
655
|
+
return json.loads(obj)
|
|
656
|
+
|
|
657
|
+
return obj
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
def make_list_lower(ls: list) -> list:
|
|
661
|
+
"""
|
|
662
|
+
Converts all elements in a list to lowercase. Ignores None values.
|
|
663
|
+
|
|
664
|
+
Args:
|
|
665
|
+
ls: The list to convert.
|
|
666
|
+
|
|
667
|
+
Returns:
|
|
668
|
+
list: The list with all strings converted to lowercase.
|
|
669
|
+
"""
|
|
670
|
+
return [item.lower() if is_instance(item, str) else item for item in ls]
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
def make_float(obj:Union[str,float,int]) -> float:
|
|
674
|
+
"""
|
|
675
|
+
Converts the input object to a float.
|
|
676
|
+
|
|
677
|
+
Args:
|
|
678
|
+
x: The object to convert.
|
|
679
|
+
|
|
680
|
+
Returns:
|
|
681
|
+
float: The float representation of the object.
|
|
682
|
+
"""
|
|
683
|
+
try:
|
|
684
|
+
return float(obj)
|
|
685
|
+
except (TypeError, ValueError):
|
|
686
|
+
return 1.0
|
|
687
|
+
|
|
688
|
+
def make_bool(obj: Union[bool, int, str]) -> Union[bool, str]:
|
|
689
|
+
"""
|
|
690
|
+
Converts the input object to a boolean representation if possible.
|
|
691
|
+
|
|
692
|
+
The function attempts to convert various objects, including integers and strings, to their boolean equivalents.
|
|
693
|
+
If the conversion is not possible, the original object is returned.
|
|
694
|
+
|
|
695
|
+
Args:
|
|
696
|
+
obj: The object to be converted.
|
|
697
|
+
|
|
698
|
+
Returns:
|
|
699
|
+
bool or original type: The boolean representation of the object if conversion is possible. Otherwise, it returns the original object.
|
|
700
|
+
|
|
701
|
+
Examples:
|
|
702
|
+
make_bool("true") -> True
|
|
703
|
+
make_bool(1) -> True
|
|
704
|
+
make_bool("0") -> False
|
|
705
|
+
make_bool(2) -> 2
|
|
706
|
+
"""
|
|
707
|
+
if is_instance(obj, bool):
|
|
708
|
+
return obj
|
|
709
|
+
if is_instance(obj, int):
|
|
710
|
+
if obj == 0:
|
|
711
|
+
return False
|
|
712
|
+
if obj == 1:
|
|
713
|
+
return True
|
|
714
|
+
if is_instance(obj, str):
|
|
715
|
+
if obj.lower() in ['0', "false"]:
|
|
716
|
+
return False
|
|
717
|
+
if obj.lower() in ['1', "true"]:
|
|
718
|
+
return True
|
|
719
|
+
return obj
|
|
720
|
+
|
|
721
|
+
def make_str(obj: any) -> str:
|
|
722
|
+
"""
|
|
723
|
+
Converts the input object to a string.
|
|
724
|
+
|
|
725
|
+
Args:
|
|
726
|
+
obj: The object to convert.
|
|
727
|
+
|
|
728
|
+
Returns:
|
|
729
|
+
str: The string representation of the object.
|
|
730
|
+
"""
|
|
731
|
+
return str(obj)
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
def get_obj_obj(obj_type: str, obj: any) -> any:
|
|
735
|
+
"""
|
|
736
|
+
Returns the object converted according to the given type string.
|
|
737
|
+
|
|
738
|
+
Args:
|
|
739
|
+
obj_type: The string representing the type to convert to.
|
|
740
|
+
obj: The object to convert.
|
|
741
|
+
|
|
742
|
+
Returns:
|
|
743
|
+
any: The object converted to the specified type.
|
|
744
|
+
"""
|
|
745
|
+
if obj_type == 'str':
|
|
746
|
+
return make_str(obj)
|
|
747
|
+
elif obj_type == 'bool':
|
|
748
|
+
return make_bool(obj)
|
|
749
|
+
elif obj_type == 'float':
|
|
750
|
+
return make_float(obj)
|
|
751
|
+
elif obj_type == 'int':
|
|
752
|
+
try:
|
|
753
|
+
return int(obj)
|
|
754
|
+
except (TypeError, ValueError):
|
|
755
|
+
return obj
|
|
756
|
+
else:
|
|
757
|
+
return obj
|
|
758
|
+
def get_len_or_num(obj: any) -> int:
|
|
759
|
+
"""
|
|
760
|
+
Returns the length of the object if it can be converted to a string, else the integer representation of the object.
|
|
761
|
+
|
|
762
|
+
Args:
|
|
763
|
+
obj: The object to process.
|
|
764
|
+
|
|
765
|
+
Returns:
|
|
766
|
+
int: The length of the object as a string or the integer representation of the object.
|
|
767
|
+
"""
|
|
768
|
+
if is_int(obj) or is_float(obj):
|
|
769
|
+
return int(obj)
|
|
770
|
+
else:
|
|
771
|
+
try:
|
|
772
|
+
return len(str(obj))
|
|
773
|
+
except (TypeError, ValueError):
|
|
774
|
+
return 0
|
|
775
|
+
def get_types_list()->list:
|
|
776
|
+
return ['list', 'bool', 'str', 'int', 'float', 'set', 'dict', 'frozenset', 'bytearray', 'bytes', 'memoryview', 'range', 'enumerate', 'zip', 'filter', 'map', 'property', 'slice', 'super', 'type', 'Exception', 'NoneType']
|
|
777
|
+
def det_bool_F(obj: (tuple or list or bool) = False):
|
|
778
|
+
"""
|
|
779
|
+
Determines if the given object is a boolean False value.
|
|
780
|
+
|
|
781
|
+
Args:
|
|
782
|
+
obj (tuple or list or bool): The object to determine the boolean False value.
|
|
783
|
+
|
|
784
|
+
Returns:
|
|
785
|
+
bool: True if the object is a boolean False value, False otherwise.
|
|
786
|
+
"""
|
|
787
|
+
if is_instance(obj, bool):
|
|
788
|
+
return obj
|
|
789
|
+
return all(obj)
|
|
790
|
+
def det_bool_T(obj: (tuple or list or bool) = False):
|
|
791
|
+
"""
|
|
792
|
+
Determines if the given object is a boolean True value.
|
|
793
|
+
|
|
794
|
+
Args:
|
|
795
|
+
obj (tuple or list or bool): The object to determine the boolean True value.
|
|
796
|
+
|
|
797
|
+
Returns:
|
|
798
|
+
bool: True if the object is a boolean True value, False otherwise.
|
|
799
|
+
"""
|
|
800
|
+
if is_instance(obj, bool):
|
|
801
|
+
return obj
|
|
802
|
+
return any(obj)
|
|
803
|
+
def T_or_F_obj_eq(event: any = '', obj: any = ''):
|
|
804
|
+
"""
|
|
805
|
+
Compares two objects and returns True if they are equal, False otherwise.
|
|
806
|
+
|
|
807
|
+
Args:
|
|
808
|
+
event (any): The first object to compare.
|
|
809
|
+
obj (any): The second object to compare.
|
|
810
|
+
|
|
811
|
+
Returns:
|
|
812
|
+
bool: True if the objects are equal, False otherwise.
|
|
813
|
+
"""
|
|
814
|
+
return True if event == obj else False
|
|
815
|
+
def ensure_integer(page_value:any, default_value:int):
|
|
816
|
+
"""
|
|
817
|
+
Ensures the given value is an integer. If not, it tries to extract
|
|
818
|
+
the numeric part of the value. If still unsuccessful, it defaults
|
|
819
|
+
to the given default value.
|
|
820
|
+
|
|
821
|
+
Parameters:
|
|
822
|
+
- page_value (str|int|any): The value to ensure as integer.
|
|
823
|
+
Non-numeric characters are stripped if necessary.
|
|
824
|
+
- default_value (int): The default value to return if conversion
|
|
825
|
+
to integer is unsuccessful.
|
|
826
|
+
|
|
827
|
+
Returns:
|
|
828
|
+
- int: The ensured integer value.
|
|
829
|
+
"""
|
|
830
|
+
# Check if page_value is already a number
|
|
831
|
+
if not is_number(page_value):
|
|
832
|
+
# Convert to string in case it's not already
|
|
833
|
+
page_value = str(page_value)
|
|
834
|
+
|
|
835
|
+
# Remove non-numeric characters from the beginning
|
|
836
|
+
while len(page_value) > 0 and page_value[0] not in '0123456789'.split(','):
|
|
837
|
+
page_value = page_value[1:]
|
|
838
|
+
|
|
839
|
+
# Remove non-numeric characters from the end
|
|
840
|
+
while len(page_value) > 0 and page_value[-1] not in '0123456789'.split(','):
|
|
841
|
+
page_value = page_value[:-1]
|
|
842
|
+
|
|
843
|
+
# If page_value is empty or still not a number, use the default value
|
|
844
|
+
if len(page_value) == 0 or not is_number(page_value):
|
|
845
|
+
return default_value
|
|
846
|
+
|
|
847
|
+
# Convert page_value to an integer and return
|
|
848
|
+
return int(page_value)
|
|
849
|
+
def if_default_return_obj(obj:any,default:any=None,default_compare:any=None):
|
|
850
|
+
if default == default_compare:
|
|
851
|
+
return obj
|
|
852
|
+
return default
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
def convert_to_number(value):
|
|
857
|
+
value_str = str(value)
|
|
858
|
+
if is_number(value_str):
|
|
859
|
+
return float(value_str) if '.' in value_str else int(value_str)
|
|
860
|
+
return value_str
|
|
861
|
+
|
|
862
|
+
def makeInt(obj):
|
|
863
|
+
if is_number(obj):
|
|
864
|
+
return int(obj)
|
|
865
|
+
return obj
|
|
866
|
+
|
|
867
|
+
def str_lower(obj):
|
|
868
|
+
try:
|
|
869
|
+
obj=str(obj).lower()
|
|
870
|
+
except Exception as e:
|
|
871
|
+
print(f"{e}")
|
|
872
|
+
return obj
|
|
873
|
+
|
|
874
|
+
def get_bool_response(bool_response,json_data):
|
|
875
|
+
if not is_instance(bool_response,bool):
|
|
876
|
+
try:
|
|
877
|
+
bool_response = json_data.get(bool_response) in [None,'',[],"",{}]
|
|
878
|
+
except:
|
|
879
|
+
pass
|
|
880
|
+
return bool_response
|
|
881
|
+
def if_true_get_string(data, key):
|
|
882
|
+
return key if data.get(key) else None
|
|
883
|
+
def find_for_string(string, parts):
|
|
884
|
+
return [part for part in parts if string.lower() in str(part).lower()]
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
def is_strings_in_string(strings, parts):
|
|
888
|
+
strings = make_list(strings)
|
|
889
|
+
for string in strings:
|
|
890
|
+
parts = find_for_string(string, parts)
|
|
891
|
+
if not parts:
|
|
892
|
+
return []
|
|
893
|
+
return parts
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
def get_alphabet_str():
|
|
900
|
+
return 'abcdefghijklmnopqrstuvwxyz'
|
|
901
|
+
def get_alphabet_upper_str():
|
|
902
|
+
alphabet_str = get_alphabet_str()
|
|
903
|
+
return alphabet_str.upper()
|
|
904
|
+
def get_alphabet_comp_str():
|
|
905
|
+
return get_alphabet_str() + get_alphabet_upper_str()
|
|
906
|
+
|
|
907
|
+
def get_alphabet():
|
|
908
|
+
alphabet_str = get_alphabet_str()
|
|
909
|
+
return break_string(alphabet_str)
|
|
910
|
+
def get_alphabet_upper():
|
|
911
|
+
alphabet_upper_str = get_alphabet_upper_str()
|
|
912
|
+
return break_string(alphabet_upper_str)
|
|
913
|
+
def get_alphabet_comp():
|
|
914
|
+
alphabet_comp_str = get_alphabet_comp_str()
|
|
915
|
+
return break_string(alphabet_comp_str)
|
|
916
|
+
|
|
917
|
+
def get_numbers_str():
|
|
918
|
+
return '0123457890'
|
|
919
|
+
def get_numbers_int():
|
|
920
|
+
numbers_str = get_numbers_str()
|
|
921
|
+
return [int(number) for number in numbers_str]
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
def get_numbers():
|
|
925
|
+
numbers_str = get_numbers_str()
|
|
926
|
+
return break_string(numbers_str)
|
|
927
|
+
def get_numbers_comp():
|
|
928
|
+
numbers_str = get_numbers()
|
|
929
|
+
numbers_int = get_numbers_int()
|
|
930
|
+
return numbers_str + numbers_int
|
|
931
|
+
def break_string(string):
|
|
932
|
+
string_str = str(string)
|
|
933
|
+
return list(string_str)
|
|
934
|
+
def is_any_instance(value):
|
|
935
|
+
for each in [dict, list, int, float]:
|
|
936
|
+
if is_instance(value, each):
|
|
937
|
+
return True
|
|
938
|
+
def get_alpha_ints(ints=True,alpha=True,lower=True,capitalize=True,string=True,listObj=True):
|
|
939
|
+
objs = [] if listObj else ""
|
|
940
|
+
if ints:
|
|
941
|
+
objs+=getInts(string=string,listObj=listObj)
|
|
942
|
+
if alpha:
|
|
943
|
+
objs+=getAlphas(lower=lower,capitalize=capitalize,listObj=listObj)
|
|
944
|
+
return objs
|
|
945
|
+
# Function: is_number
|
|
946
|
+
# Function: is_str
|
|
947
|
+
# Function: is_int
|
|
948
|
+
# Function: get_type
|
|
949
|
+
# Function: is_float
|
|
950
|
+
# Function: is_object
|
|
951
|
+
# Function: is_bool
|
|
952
|
+
# Function: is_list
|
|
953
|
+
# Function: is_tuple
|
|
954
|
+
# Function: is_set
|
|
955
|
+
# Function: is_dict
|
|
956
|
+
# Function: is_frozenset
|
|
957
|
+
# Function: is_bytearray
|
|
958
|
+
# Function: is_bytes
|
|
959
|
+
# Function: is_memoryview
|
|
960
|
+
# Function: is_range
|
|
961
|
+
# Function: is_enumerate
|
|
962
|
+
# Function: is_zip
|
|
963
|
+
# Function: is_filter
|
|
964
|
+
# Function: is_map
|
|
965
|
+
# Function: is_property
|
|
966
|
+
# Function: is_slice
|
|
967
|
+
# Function: is_super
|
|
968
|
+
# Function: is_type
|
|
969
|
+
# Function: is_Exception
|
|
970
|
+
# Function: is_none
|
|
971
|
+
# Function: is_str_convertible_dict
|
|
972
|
+
# Function: is_dict_or_convertable
|
|
973
|
+
# Function: dict_check_conversion
|
|
974
|
+
# Function: make_list
|
|
975
|
+
# Function: make_list_lower
|
|
976
|
+
# Function: make_float
|
|
977
|
+
# Function: make_bool
|
|
978
|
+
# Function: make_str
|
|
979
|
+
# Function: get_obj_obj
|
|
980
|
+
# Function: get_len_or_num
|
|
981
|
+
# Function: get_types_list
|