xulbux 1.6.4__tar.gz → 1.6.6__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.
Potentially problematic release.
This version of xulbux might be problematic. Click here for more details.
- {xulbux-1.6.4/src/xulbux.egg-info → xulbux-1.6.6}/PKG-INFO +19 -17
- {xulbux-1.6.4 → xulbux-1.6.6}/README.md +10 -10
- {xulbux-1.6.4 → xulbux-1.6.6}/pyproject.toml +13 -11
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/__init__.py +2 -2
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/_cli_.py +9 -9
- xulbux-1.6.6/src/xulbux/_consts_.py +158 -0
- xulbux-1.6.6/src/xulbux/xx_code.py +100 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_color.py +49 -79
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_console.py +197 -109
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_data.py +177 -126
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_env_path.py +1 -5
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_file.py +1 -1
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_format_codes.py +40 -38
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_json.py +2 -5
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_path.py +5 -5
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_regex.py +18 -20
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_string.py +28 -82
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux/xx_system.py +5 -13
- {xulbux-1.6.4 → xulbux-1.6.6/src/xulbux.egg-info}/PKG-INFO +19 -17
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux.egg-info/requires.txt +2 -0
- xulbux-1.6.6/tests/test_console_info.py +37 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/tests/test_data.py +2 -2
- xulbux-1.6.4/src/xulbux/_consts_.py +0 -145
- xulbux-1.6.4/src/xulbux/xx_code.py +0 -105
- xulbux-1.6.4/tests/test_console_info.py +0 -19
- {xulbux-1.6.4 → xulbux-1.6.6}/LICENSE +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/setup.cfg +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux.egg-info/SOURCES.txt +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux.egg-info/dependency_links.txt +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux.egg-info/entry_points.txt +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/src/xulbux.egg-info/top_level.txt +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/tests/test_color.py +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/tests/test_color_types.py +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/tests/test_env_vars.py +0 -0
- {xulbux-1.6.4 → xulbux-1.6.6}/tests/test_format_codes.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: xulbux
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.6
|
|
4
4
|
Summary: A library which includes a lot of really helpful functions.
|
|
5
5
|
Author-email: XulbuX <xulbux.real@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -25,12 +25,12 @@ License: MIT License
|
|
|
25
25
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
26
|
SOFTWARE.
|
|
27
27
|
|
|
28
|
-
Project-URL: Bug Reports, https://github.com/XulbuX
|
|
29
|
-
Project-URL: Changelog, https://github.com/XulbuX
|
|
30
|
-
Project-URL: Documentation, https://github.com/XulbuX
|
|
31
|
-
Project-URL: Homepage, https://github.com/XulbuX
|
|
32
|
-
Project-URL: License, https://github.com/XulbuX
|
|
33
|
-
Project-URL: Source Code, https://github.com/XulbuX
|
|
28
|
+
Project-URL: Bug Reports, https://github.com/XulbuX/PythonLibraryXulbuX/issues
|
|
29
|
+
Project-URL: Changelog, https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md
|
|
30
|
+
Project-URL: Documentation, https://github.com/XulbuX/PythonLibraryXulbuX/wiki
|
|
31
|
+
Project-URL: Homepage, https://github.com/XulbuX/PythonLibraryXulbuX
|
|
32
|
+
Project-URL: License, https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/LICENSE
|
|
33
|
+
Project-URL: Source Code, https://github.com/XulbuX/PythonLibraryXulbuX/tree/main/src
|
|
34
34
|
Keywords: xulbux,python,library,utility,helper,functions,tools,classes,types,methods,cmd,console,code,color,data,structures,env,environment,file,format,json,path,regex,string,system,operations,presets
|
|
35
35
|
Classifier: Intended Audience :: Developers
|
|
36
36
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -45,6 +45,7 @@ Description-Content-Type: text/markdown
|
|
|
45
45
|
License-File: LICENSE
|
|
46
46
|
Requires-Dist: keyboard>=0.13.5
|
|
47
47
|
Requires-Dist: mouse>=0.7.1
|
|
48
|
+
Requires-Dist: prompt_toolkit>=3.0.41
|
|
48
49
|
Requires-Dist: pyperclip>=1.9.0
|
|
49
50
|
Requires-Dist: regex>=2023.10.3
|
|
50
51
|
Provides-Extra: dev
|
|
@@ -52,13 +53,14 @@ Requires-Dist: pytest>=7.4.2; extra == "dev"
|
|
|
52
53
|
Requires-Dist: black>=23.7.0; extra == "dev"
|
|
53
54
|
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
54
55
|
Requires-Dist: flake8>=6.1.0; extra == "dev"
|
|
56
|
+
Requires-Dist: flake8-pyproject>=1.2.3; extra == "dev"
|
|
55
57
|
|
|
56
58
|
# **$\color{#8085FF}\Huge\textsf{XulbuX}$**
|
|
57
59
|
|
|
58
60
|
**$\color{#8085FF}\textsf{XulbuX}$** is a library which includes a lot of really helpful classes, types and functions.
|
|
59
61
|
|
|
60
|
-
For precise information about the library, see the library's [Wiki page](https://github.com/XulbuX
|
|
61
|
-
For the libraries latest changes, see the [change log](https://github.com/XulbuX
|
|
62
|
+
For precise information about the library, see the library's [Wiki page](https://github.com/XulbuX/PythonLibraryXulbuX/wiki).<br>
|
|
63
|
+
For the libraries latest changes, see the [change log](https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md).
|
|
62
64
|
|
|
63
65
|
|
|
64
66
|
## Installation
|
|
@@ -90,17 +92,17 @@ from xulbux import rgba, hsla, hexa
|
|
|
90
92
|
|
|
91
93
|
| | |
|
|
92
94
|
| :--------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------- |
|
|
93
|
-
| <h3>[`xx_code`](https://github.com/XulbuX
|
|
94
|
-
| <h3>[`xx_color`](https://github.com/XulbuX
|
|
95
|
-
| <h3>[`xx_console`](https://github.com/XulbuX
|
|
96
|
-
| <h3>[`xx_data`](https://github.com/XulbuX
|
|
97
|
-
| <h3>[`xx_env_path`](https://github.com/XulbuX
|
|
98
|
-
| <h3>[`xx_file`](https://github.com/XulbuX
|
|
99
|
-
| <h3>[`xx_format_codes`](https://github.com/XulbuX
|
|
95
|
+
| <h3>[`xx_code`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_code)</h3> | advanced code-string operations (*changing the indent, finding function calls, ...*) |
|
|
96
|
+
| <h3>[`xx_color`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_color)</h3> | everything around colors (*converting, blending, searching colors in strings, ...*) |
|
|
97
|
+
| <h3>[`xx_console`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_console)</h3> | advanced actions related to the console (*pretty logging, advanced inputs, ...*) |
|
|
98
|
+
| <h3>[`xx_data`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_data)</h3> | advanced operations with data structures (*compare, generate path ID's, pretty print/format, ...*) |
|
|
99
|
+
| <h3>[`xx_env_path`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_env_path)</h3> | getting and editing the PATH variable (*get paths, check for paths, add paths, ...*) |
|
|
100
|
+
| <h3>[`xx_file`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_file)</h3> | advanced working with files (*create files, rename file-extensions, ...*) |
|
|
101
|
+
| <h3>[`xx_format_codes`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_format_codes)</h3> | easy pretty printing with custom format codes (*print, inputs, custom format codes to ANSI, ...*) |
|
|
100
102
|
| <h3>`xx_json`</h3> | advanced working with json files (*read, create, update, ...*) |
|
|
101
103
|
| <h3>`xx_path`</h3> | advanced path operations (*get paths, smart-extend relative paths, delete paths, ...*) |
|
|
102
104
|
| <h3>`xx_regex`</h3> | generated regex pattern-templates (*match bracket- and quote pairs, match colors, ...*) |
|
|
103
|
-
| <h3>[`xx_string`](https://github.com/XulbuX
|
|
105
|
+
| <h3>[`xx_string`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_string)</h3> | helpful actions when working with strings. (*normalize, escape, decompose, ...*) |
|
|
104
106
|
| <h3>`xx_system`</h3> | advanced system actions (*restart with message, check installed Python libs, ...*) |
|
|
105
107
|
|
|
106
108
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
**$\color{#8085FF}\textsf{XulbuX}$** is a library which includes a lot of really helpful classes, types and functions.
|
|
4
4
|
|
|
5
|
-
For precise information about the library, see the library's [Wiki page](https://github.com/XulbuX
|
|
6
|
-
For the libraries latest changes, see the [change log](https://github.com/XulbuX
|
|
5
|
+
For precise information about the library, see the library's [Wiki page](https://github.com/XulbuX/PythonLibraryXulbuX/wiki).<br>
|
|
6
|
+
For the libraries latest changes, see the [change log](https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md).
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
@@ -35,17 +35,17 @@ from xulbux import rgba, hsla, hexa
|
|
|
35
35
|
|
|
36
36
|
| | |
|
|
37
37
|
| :--------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------- |
|
|
38
|
-
| <h3>[`xx_code`](https://github.com/XulbuX
|
|
39
|
-
| <h3>[`xx_color`](https://github.com/XulbuX
|
|
40
|
-
| <h3>[`xx_console`](https://github.com/XulbuX
|
|
41
|
-
| <h3>[`xx_data`](https://github.com/XulbuX
|
|
42
|
-
| <h3>[`xx_env_path`](https://github.com/XulbuX
|
|
43
|
-
| <h3>[`xx_file`](https://github.com/XulbuX
|
|
44
|
-
| <h3>[`xx_format_codes`](https://github.com/XulbuX
|
|
38
|
+
| <h3>[`xx_code`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_code)</h3> | advanced code-string operations (*changing the indent, finding function calls, ...*) |
|
|
39
|
+
| <h3>[`xx_color`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_color)</h3> | everything around colors (*converting, blending, searching colors in strings, ...*) |
|
|
40
|
+
| <h3>[`xx_console`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_console)</h3> | advanced actions related to the console (*pretty logging, advanced inputs, ...*) |
|
|
41
|
+
| <h3>[`xx_data`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_data)</h3> | advanced operations with data structures (*compare, generate path ID's, pretty print/format, ...*) |
|
|
42
|
+
| <h3>[`xx_env_path`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_env_path)</h3> | getting and editing the PATH variable (*get paths, check for paths, add paths, ...*) |
|
|
43
|
+
| <h3>[`xx_file`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_file)</h3> | advanced working with files (*create files, rename file-extensions, ...*) |
|
|
44
|
+
| <h3>[`xx_format_codes`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_format_codes)</h3> | easy pretty printing with custom format codes (*print, inputs, custom format codes to ANSI, ...*) |
|
|
45
45
|
| <h3>`xx_json`</h3> | advanced working with json files (*read, create, update, ...*) |
|
|
46
46
|
| <h3>`xx_path`</h3> | advanced path operations (*get paths, smart-extend relative paths, delete paths, ...*) |
|
|
47
47
|
| <h3>`xx_regex`</h3> | generated regex pattern-templates (*match bracket- and quote pairs, match colors, ...*) |
|
|
48
|
-
| <h3>[`xx_string`](https://github.com/XulbuX
|
|
48
|
+
| <h3>[`xx_string`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_string)</h3> | helpful actions when working with strings. (*normalize, escape, decompose, ...*) |
|
|
49
49
|
| <h3>`xx_system`</h3> | advanced system actions (*restart with message, check installed Python libs, ...*) |
|
|
50
50
|
|
|
51
51
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "xulbux"
|
|
7
|
-
version = "1.6.
|
|
7
|
+
version = "1.6.6"
|
|
8
8
|
authors = [{ name = "XulbuX", email = "xulbux.real@gmail.com" }]
|
|
9
9
|
description = "A library which includes a lot of really helpful functions."
|
|
10
10
|
readme = "README.md"
|
|
@@ -13,6 +13,7 @@ requires-python = ">=3.10.0"
|
|
|
13
13
|
dependencies = [
|
|
14
14
|
"keyboard>=0.13.5",
|
|
15
15
|
"mouse>=0.7.1",
|
|
16
|
+
"prompt_toolkit>=3.0.41",
|
|
16
17
|
"pyperclip>=1.9.0",
|
|
17
18
|
"regex>=2023.10.3",
|
|
18
19
|
]
|
|
@@ -21,6 +22,7 @@ optional-dependencies = { dev = [
|
|
|
21
22
|
"black>=23.7.0",
|
|
22
23
|
"isort>=5.12.0",
|
|
23
24
|
"flake8>=6.1.0",
|
|
25
|
+
"flake8-pyproject>=1.2.3",
|
|
24
26
|
] }
|
|
25
27
|
classifiers = [
|
|
26
28
|
"Intended Audience :: Developers",
|
|
@@ -63,12 +65,12 @@ keywords = [
|
|
|
63
65
|
]
|
|
64
66
|
|
|
65
67
|
[project.urls]
|
|
66
|
-
"Bug Reports" = "https://github.com/XulbuX
|
|
67
|
-
"Changelog" = "https://github.com/XulbuX
|
|
68
|
-
"Documentation" = "https://github.com/XulbuX
|
|
69
|
-
"Homepage" = "https://github.com/XulbuX
|
|
70
|
-
"License" = "https://github.com/XulbuX
|
|
71
|
-
"Source Code" = "https://github.com/XulbuX
|
|
68
|
+
"Bug Reports" = "https://github.com/XulbuX/PythonLibraryXulbuX/issues"
|
|
69
|
+
"Changelog" = "https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md"
|
|
70
|
+
"Documentation" = "https://github.com/XulbuX/PythonLibraryXulbuX/wiki"
|
|
71
|
+
"Homepage" = "https://github.com/XulbuX/PythonLibraryXulbuX"
|
|
72
|
+
"License" = "https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/LICENSE"
|
|
73
|
+
"Source Code" = "https://github.com/XulbuX/PythonLibraryXulbuX/tree/main/src"
|
|
72
74
|
|
|
73
75
|
|
|
74
76
|
[project.scripts]
|
|
@@ -103,11 +105,11 @@ use_parentheses = true
|
|
|
103
105
|
ensure_newline_before_comments = true
|
|
104
106
|
|
|
105
107
|
[tool.flake8]
|
|
108
|
+
max-complexity = 12
|
|
106
109
|
max-line-length = 127
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
per-file-ignores = ["__init__.py:F401,F403"]
|
|
110
|
+
select = ["E", "F", "W", "C90"]
|
|
111
|
+
extend-ignore = ["E203", "E266", "W503"]
|
|
112
|
+
per-file-ignores = ["__init__.py:F403,F405"]
|
|
111
113
|
|
|
112
114
|
[tool.setuptools]
|
|
113
115
|
packages = ["xulbux"]
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
• REGEX PATTERN TEMPLATES xx.Regex
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
|
-
__version__ = "1.6.
|
|
22
|
+
__version__ = "1.6.6"
|
|
23
23
|
__author__ = "XulbuX"
|
|
24
24
|
__email__ = "xulbux.real@gmail.com"
|
|
25
25
|
__license__ = "MIT"
|
|
26
26
|
__copyright__ = "Copyright (c) 2024 XulbuX"
|
|
27
|
-
__url__ = "https://github.com/XulbuX
|
|
27
|
+
__url__ = "https://github.com/XulbuX/PythonLibraryXulbuX"
|
|
28
28
|
__description__ = "A library which includes a lot of really helpful functions."
|
|
29
29
|
__all__ = [
|
|
30
30
|
"_consts_",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from . import __version__
|
|
2
|
-
from ._consts_ import
|
|
2
|
+
from ._consts_ import COLOR
|
|
3
3
|
from .xx_format_codes import FormatCodes
|
|
4
4
|
from .xx_console import Console
|
|
5
5
|
|
|
@@ -7,20 +7,20 @@ from .xx_console import Console
|
|
|
7
7
|
def help_command():
|
|
8
8
|
"""Show some info about the library, with a brief explanation of how to use it."""
|
|
9
9
|
color = {
|
|
10
|
-
"lib":
|
|
11
|
-
"import":
|
|
12
|
-
"class":
|
|
13
|
-
"types":
|
|
14
|
-
"punctuators":
|
|
10
|
+
"lib": COLOR.ice,
|
|
11
|
+
"import": COLOR.red,
|
|
12
|
+
"class": COLOR.lavender,
|
|
13
|
+
"types": COLOR.lightblue,
|
|
14
|
+
"punctuators": COLOR.darkgray,
|
|
15
15
|
}
|
|
16
16
|
FormatCodes.print(
|
|
17
17
|
rf""" [_|b|#7075FF] __ __
|
|
18
18
|
[b|#7075FF] _ __ __ __/ / / /_ __ ___ __
|
|
19
19
|
[b|#7075FF] | |/ // / / / / / __ \/ / / | |/ /
|
|
20
20
|
[b|#7075FF] > , </ /_/ / /_/ /_/ / /_/ /> , <
|
|
21
|
-
[b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|BG:{
|
|
21
|
+
[b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|BG:{COLOR.gray}|#000] v[b]{__version__} [*]
|
|
22
22
|
|
|
23
|
-
[i|{
|
|
23
|
+
[i|{COLOR.coral}]A TON OF COOL FUNCTIONS, YOU NEED![*]
|
|
24
24
|
|
|
25
25
|
[b|#75A2FF]Usage:[*]
|
|
26
26
|
[{color['punctuators']}]# GENERAL LIBRARY[*]
|
|
@@ -48,6 +48,6 @@ def help_command():
|
|
|
48
48
|
[_]
|
|
49
49
|
[dim](Press any key to exit...)
|
|
50
50
|
""",
|
|
51
|
-
default_color=
|
|
51
|
+
default_color=COLOR.text
|
|
52
52
|
)
|
|
53
53
|
Console.pause_exit(pause=True)
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import TypeAlias
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
FormattableString: TypeAlias = str
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class COLOR:
|
|
10
|
+
"""Color presets used in the XulbuX library."""
|
|
11
|
+
|
|
12
|
+
text = "#A5D6FF"
|
|
13
|
+
white = "#F1F2FF"
|
|
14
|
+
lightgray = "#B6B7C0"
|
|
15
|
+
gray = "#7B7C8D"
|
|
16
|
+
darkgray = "#67686C"
|
|
17
|
+
black = "#202125"
|
|
18
|
+
red = "#FF606A"
|
|
19
|
+
coral = "#FF7069"
|
|
20
|
+
orange = "#FF876A"
|
|
21
|
+
tangerine = "#FF9962"
|
|
22
|
+
gold = "#FFAF60"
|
|
23
|
+
yellow = "#FFD260"
|
|
24
|
+
green = "#7EE787"
|
|
25
|
+
teal = "#50EAAF"
|
|
26
|
+
cyan = "#3EDEE6"
|
|
27
|
+
ice = "#77DBEF"
|
|
28
|
+
lightblue = "#60AAFF"
|
|
29
|
+
blue = "#8085FF"
|
|
30
|
+
lavender = "#9B7DFF"
|
|
31
|
+
purple = "#AD68FF"
|
|
32
|
+
magenta = "#C860FF"
|
|
33
|
+
pink = "#F162EF"
|
|
34
|
+
rose = "#FF609F"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class _AllTextCharacters:
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass
|
|
42
|
+
class CHARS:
|
|
43
|
+
"""Strings with only certain text characters."""
|
|
44
|
+
|
|
45
|
+
# CODE TO SIGNAL, ALL CHARACTERS ARE ALLOWED
|
|
46
|
+
all = _AllTextCharacters
|
|
47
|
+
|
|
48
|
+
# DIGIT SETS
|
|
49
|
+
digits: str = "0123456789"
|
|
50
|
+
float_digits: str = digits + "."
|
|
51
|
+
hex_digits: str = digits + "#abcdefABCDEF"
|
|
52
|
+
|
|
53
|
+
# LETTER CATEGORIES
|
|
54
|
+
lowercase: str = "abcdefghijklmnopqrstuvwxyz"
|
|
55
|
+
lowercase_extended: str = lowercase + "äëïöüÿàèìòùáéíóúýâêîôûãñõåæç"
|
|
56
|
+
uppercase: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
57
|
+
uppercase_extended: str = uppercase + "ÄËÏÖÜÀÈÌÒÙÁÉÍÓÚÝÂÊÎÔÛÃÑÕÅÆÇß"
|
|
58
|
+
|
|
59
|
+
# COMBINED LETTER SETS
|
|
60
|
+
letters: str = lowercase + uppercase
|
|
61
|
+
letters_extended: str = lowercase_extended + uppercase_extended
|
|
62
|
+
|
|
63
|
+
# ASCII sets
|
|
64
|
+
special_ascii: str = " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
|
65
|
+
special_ascii_extended: str = special_ascii + "ø£Ø×ƒªº¿®¬½¼¡«»░▒▓│┤©╣║╗╝¢¥┐└┴┬├─┼╚╔╩╦╠═╬¤ðÐı┘┌█▄¦▀µþÞ¯´≡±‗¾¶§÷¸°¨·¹³²■ "
|
|
66
|
+
standard_ascii: str = special_ascii + digits + letters
|
|
67
|
+
full_ascii: str = special_ascii_extended + digits + letters_extended
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class ANSI:
|
|
71
|
+
"""Constants and class-methods for use of ANSI escape codes."""
|
|
72
|
+
|
|
73
|
+
escaped_char: str = "\\x1b"
|
|
74
|
+
CHAR = char = "\x1b"
|
|
75
|
+
START = start = "["
|
|
76
|
+
SEP = sep = ";"
|
|
77
|
+
END = end = "m"
|
|
78
|
+
default_color_modifiers: dict[str, str] = {"lighten": "+l", "darken": "-d"}
|
|
79
|
+
|
|
80
|
+
@classmethod
|
|
81
|
+
def seq(cls, parts: int = 1) -> str:
|
|
82
|
+
"""Generate an ANSI sequence with `parts` amount of placeholders."""
|
|
83
|
+
return cls.CHAR + cls.START + cls.SEP.join(["{}" for _ in range(parts)]) + cls.END
|
|
84
|
+
|
|
85
|
+
seq_color: FormattableString = CHAR + START + "38" + SEP + "2" + SEP + "{}" + SEP + "{}" + SEP + "{}" + END
|
|
86
|
+
seq_bg_color: FormattableString = CHAR + START + "48" + SEP + "2" + SEP + "{}" + SEP + "{}" + SEP + "{}" + END
|
|
87
|
+
|
|
88
|
+
color_map: list[str] = [
|
|
89
|
+
########### DEFAULT CONSOLE COLOR NAMES ############
|
|
90
|
+
"black",
|
|
91
|
+
"red",
|
|
92
|
+
"green",
|
|
93
|
+
"yellow",
|
|
94
|
+
"blue",
|
|
95
|
+
"magenta",
|
|
96
|
+
"cyan",
|
|
97
|
+
"white",
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
codes_map: dict[str | tuple[str, ...], int] = {
|
|
101
|
+
################# SPECIFIC RESETS ##################
|
|
102
|
+
"_": 0,
|
|
103
|
+
("_bold", "_b"): 22,
|
|
104
|
+
("_dim", "_d"): 22,
|
|
105
|
+
("_italic", "_i"): 23,
|
|
106
|
+
("_underline", "_u"): 24,
|
|
107
|
+
("_double-underline", "_du"): 24,
|
|
108
|
+
("_inverse", "_invert", "_in"): 27,
|
|
109
|
+
("_hidden", "_hide", "_h"): 28,
|
|
110
|
+
("_strikethrough", "_s"): 29,
|
|
111
|
+
("_color", "_c"): 39,
|
|
112
|
+
("_background", "_bg"): 49,
|
|
113
|
+
################### TEXT STYLES ####################
|
|
114
|
+
("bold", "b"): 1,
|
|
115
|
+
("dim", "d"): 2,
|
|
116
|
+
("italic", "i"): 3,
|
|
117
|
+
("underline", "u"): 4,
|
|
118
|
+
("inverse", "invert", "in"): 7,
|
|
119
|
+
("hidden", "hide", "h"): 8,
|
|
120
|
+
("strikethrough", "s"): 9,
|
|
121
|
+
("double-underline", "du"): 21,
|
|
122
|
+
################## DEFAULT COLORS ##################
|
|
123
|
+
"black": 30,
|
|
124
|
+
"red": 31,
|
|
125
|
+
"green": 32,
|
|
126
|
+
"yellow": 33,
|
|
127
|
+
"blue": 34,
|
|
128
|
+
"magenta": 35,
|
|
129
|
+
"cyan": 36,
|
|
130
|
+
"white": 37,
|
|
131
|
+
############## BRIGHT DEFAULT COLORS ###############
|
|
132
|
+
"br:black": 90,
|
|
133
|
+
"br:red": 91,
|
|
134
|
+
"br:green": 92,
|
|
135
|
+
"br:yellow": 93,
|
|
136
|
+
"br:blue": 94,
|
|
137
|
+
"br:magenta": 95,
|
|
138
|
+
"br:cyan": 96,
|
|
139
|
+
"br:white": 97,
|
|
140
|
+
############ DEFAULT BACKGROUND COLORS #############
|
|
141
|
+
"bg:black": 40,
|
|
142
|
+
"bg:red": 41,
|
|
143
|
+
"bg:green": 42,
|
|
144
|
+
"bg:yellow": 43,
|
|
145
|
+
"bg:blue": 44,
|
|
146
|
+
"bg:magenta": 45,
|
|
147
|
+
"bg:cyan": 46,
|
|
148
|
+
"bg:white": 47,
|
|
149
|
+
######### BRIGHT DEFAULT BACKGROUND COLORS #########
|
|
150
|
+
"bg:br:black": 100,
|
|
151
|
+
"bg:br:red": 101,
|
|
152
|
+
"bg:br:green": 102,
|
|
153
|
+
"bg:br:yellow": 103,
|
|
154
|
+
"bg:br:blue": 104,
|
|
155
|
+
"bg:br:magenta": 105,
|
|
156
|
+
"bg:br:cyan": 106,
|
|
157
|
+
"bg:br:white": 107,
|
|
158
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from .xx_string import String
|
|
2
|
+
from .xx_regex import Regex
|
|
3
|
+
from .xx_data import Data
|
|
4
|
+
|
|
5
|
+
import regex as _rx
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Code:
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def add_indent(code: str, indent: int) -> str:
|
|
12
|
+
"""Adds `indent` spaces at the beginning of each line."""
|
|
13
|
+
indented_lines = [" " * indent + line for line in code.splitlines()]
|
|
14
|
+
return "\n".join(indented_lines)
|
|
15
|
+
|
|
16
|
+
@staticmethod
|
|
17
|
+
def get_tab_spaces(code: str) -> int:
|
|
18
|
+
"""Will try to get the amount of spaces used for indentation."""
|
|
19
|
+
code_lines = String.get_lines(code, remove_empty_lines=True)
|
|
20
|
+
indents = [len(line) - len(line.lstrip()) for line in code_lines]
|
|
21
|
+
non_zero_indents = [i for i in indents if i > 0]
|
|
22
|
+
return min(non_zero_indents) if non_zero_indents else 0
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def change_tab_size(code: str, new_tab_size: int, remove_empty_lines: bool = False) -> str:
|
|
26
|
+
"""Replaces all tabs with `new_tab_size` spaces.\n
|
|
27
|
+
----------------------------------------------------------------------------------
|
|
28
|
+
If `remove_empty_lines` is `True`, empty lines will be removed in the process."""
|
|
29
|
+
code_lines = String.get_lines(code, remove_empty_lines=True)
|
|
30
|
+
lines = code_lines if remove_empty_lines else String.get_lines(code)
|
|
31
|
+
tab_spaces = Code.get_tab_spaces(code)
|
|
32
|
+
if (tab_spaces == new_tab_size) or tab_spaces == 0:
|
|
33
|
+
if remove_empty_lines:
|
|
34
|
+
return "\n".join(code_lines)
|
|
35
|
+
return code
|
|
36
|
+
result = []
|
|
37
|
+
for line in lines:
|
|
38
|
+
stripped = line.lstrip()
|
|
39
|
+
indent_level = (len(line) - len(stripped)) // tab_spaces
|
|
40
|
+
new_indent = " " * (indent_level * new_tab_size)
|
|
41
|
+
result.append(new_indent + stripped)
|
|
42
|
+
return "\n".join(result)
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def get_func_calls(code: str) -> list:
|
|
46
|
+
"""Will try to get all function calls and return them as a list."""
|
|
47
|
+
funcs = _rx.findall(r"(?i)" + Regex.func_call(), code)
|
|
48
|
+
nested_func_calls = []
|
|
49
|
+
for _, func_attrs in funcs:
|
|
50
|
+
nested_calls = _rx.findall(r"(?i)" + Regex.func_call(), func_attrs)
|
|
51
|
+
if nested_calls:
|
|
52
|
+
nested_func_calls.extend(nested_calls)
|
|
53
|
+
return Data.remove_duplicates(funcs + nested_func_calls)
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def is_js(code: str, funcs: list = ["__", "$t", "$lang"]) -> bool:
|
|
57
|
+
"""Will check if the code is very likely to be JavaScript."""
|
|
58
|
+
funcs = "|".join(funcs)
|
|
59
|
+
js_pattern = _rx.compile(
|
|
60
|
+
Regex.outside_strings(
|
|
61
|
+
r"""^(?:
|
|
62
|
+
(\$[\w_]+)\s* # JQUERY-STYLE VARIABLES
|
|
63
|
+
|(\$[\w_]+\s*\() # JQUERY-STYLE FUNCTION CALLS
|
|
64
|
+
|((""" + funcs + r")" + Regex.brackets("()") + r"""\s*) # PREDEFINED FUNCTION CALLS
|
|
65
|
+
|(\bfunction\s*\() # FUNCTION DECLARATIONS
|
|
66
|
+
|(\b(var|let|const)\s+[\w_]+\s*=) # VARIABLE DECLARATIONS
|
|
67
|
+
|(\b(if|for|while|switch)\s*\() # CONTROL STRUCTURES
|
|
68
|
+
|(\b(return|throw)\s+) # RETURN OR THROW STATEMENTS
|
|
69
|
+
|(\bnew\s+[\w_]+\() # OBJECT INSTANTIATION
|
|
70
|
+
|(\b[\w_]+\s*=>\s*{) # ARROW FUNCTIONS
|
|
71
|
+
|(\b(true|false|null|undefined)\b) # JAVASCRIPT LITERALS
|
|
72
|
+
|(\b(document|window|console)\.) # BROWSER OBJECTS
|
|
73
|
+
|(\b[\w_]+\.(forEach|map|filter|reduce)\() # ARRAY METHODS
|
|
74
|
+
|(/[^/\n\r]*?/[gimsuy]*) # REGULAR EXPRESSIONS
|
|
75
|
+
|(===|!==|\+\+|--|\|\||&&) # JAVASCRIPT-SPECIFIC OPERATORS
|
|
76
|
+
|(\bclass\s+[\w_]+) # CLASS DECLARATIONS
|
|
77
|
+
|(\bimport\s+.*?from\s+) # IMPORT STATEMENTS
|
|
78
|
+
|(\bexport\s+(default\s+)?) # EXPORT STATEMENTS
|
|
79
|
+
|(\basync\s+function) # ASYNC FUNCTIONS
|
|
80
|
+
|(\bawait\s+) # AWAIT KEYWORD
|
|
81
|
+
|(\btry\s*{) # TRY-CATCH BLOCKS
|
|
82
|
+
|(\bcatch\s*\()
|
|
83
|
+
|(\bfinally\s*{)
|
|
84
|
+
|(\byield\s+) # GENERATOR FUNCTIONS
|
|
85
|
+
|(\[.*?\]\s*=) # DESTRUCTURING ASSIGNMENT
|
|
86
|
+
|(\.\.\.) # SPREAD OPERATOR
|
|
87
|
+
|(==|!=|>=|<=|>|<) # COMPARISON OPERATORS
|
|
88
|
+
|(\+=|-=|\*=|/=|%=|\*\*=) # COMPOUND ASSIGNMENT OPERATORS
|
|
89
|
+
|(\+|-|\*|/|%|\*\*) # ARITHMETIC OPERATORS
|
|
90
|
+
|(&|\||\^|~|<<|>>|>>>) # BITWISE OPERATORS
|
|
91
|
+
|(\?|:) # TERNARY OPERATOR
|
|
92
|
+
|(\bin\b) # IN OPERATOR
|
|
93
|
+
|(\binstanceof\b) # INSTANCEOF OPERATOR
|
|
94
|
+
|(\bdelete\b) # DELETE OPERATOR
|
|
95
|
+
|(\btypeof\b) # TYPEOF OPERATOR
|
|
96
|
+
|(\bvoid\b) # VOID OPERATOR
|
|
97
|
+
)[\s\S]*$"""
|
|
98
|
+
), _rx.VERBOSE | _rx.IGNORECASE
|
|
99
|
+
)
|
|
100
|
+
return bool(js_pattern.fullmatch(code))
|