xulbux 1.6.8__py3-none-any.whl → 1.7.0__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.
Potentially problematic release.
This version of xulbux might be problematic. Click here for more details.
- xulbux/__init__.py +3 -35
- xulbux/_cli_.py +21 -28
- xulbux/_consts_.py +1 -0
- xulbux/xx_code.py +62 -46
- xulbux/xx_color.py +223 -159
- xulbux/xx_console.py +152 -78
- xulbux/xx_data.py +79 -71
- xulbux/xx_env_path.py +6 -9
- xulbux/xx_file.py +22 -26
- xulbux/xx_format_codes.py +55 -33
- xulbux/xx_json.py +107 -51
- xulbux/xx_path.py +74 -24
- xulbux/xx_regex.py +11 -10
- xulbux/xx_string.py +4 -1
- xulbux/xx_system.py +6 -10
- {xulbux-1.6.8.dist-info → xulbux-1.7.0.dist-info}/METADATA +18 -39
- xulbux-1.7.0.dist-info/RECORD +21 -0
- {xulbux-1.6.8.dist-info → xulbux-1.7.0.dist-info}/WHEEL +1 -1
- xulbux-1.6.8.dist-info/RECORD +0 -21
- {xulbux-1.6.8.dist-info → xulbux-1.7.0.dist-info}/entry_points.txt +0 -0
- {xulbux-1.6.8.dist-info → xulbux-1.7.0.dist-info/licenses}/LICENSE +0 -0
- {xulbux-1.6.8.dist-info → xulbux-1.7.0.dist-info}/top_level.txt +0 -0
xulbux/__init__.py
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
""
|
|
2
|
-
>>> import xulbux as xx
|
|
3
|
-
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
4
|
-
• CUSTOM TYPES:
|
|
5
|
-
• rgba(int,int,int,float)
|
|
6
|
-
• hsla(int,int,int,float)
|
|
7
|
-
• hexa(str)
|
|
8
|
-
• PATH OPERATIONS xx.Path
|
|
9
|
-
• FILE OPERATIONS xx.File
|
|
10
|
-
• JSON FILE OPERATIONS xx.Json
|
|
11
|
-
• SYSTEM ACTIONS xx.System
|
|
12
|
-
• MANAGE THE ENV PATH VAR xx.EnvPath
|
|
13
|
-
• CONSOLE LOG AND ACTIONS xx.Console
|
|
14
|
-
• EASY PRETTY PRINTING xx.FormatCodes
|
|
15
|
-
• WORKING WITH COLORS xx.Color
|
|
16
|
-
• DATA OPERATIONS xx.Data
|
|
17
|
-
• STRING OPERATIONS xx.String
|
|
18
|
-
• CODE STRING OPERATIONS xx.Code
|
|
19
|
-
• REGEX PATTERN TEMPLATES xx.Regex
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
__version__ = "1.6.8"
|
|
1
|
+
__version__ = "1.7.0"
|
|
23
2
|
__author__ = "XulbuX"
|
|
24
3
|
__email__ = "xulbux.real@gmail.com"
|
|
25
4
|
__license__ = "MIT"
|
|
@@ -27,19 +6,8 @@ __copyright__ = "Copyright (c) 2024 XulbuX"
|
|
|
27
6
|
__url__ = "https://github.com/XulbuX/PythonLibraryXulbuX"
|
|
28
7
|
__description__ = "A library which includes a lot of really helpful functions."
|
|
29
8
|
__all__ = [
|
|
30
|
-
"_consts_",
|
|
31
|
-
"
|
|
32
|
-
"xx_code",
|
|
33
|
-
"xx_color",
|
|
34
|
-
"xx_data",
|
|
35
|
-
"xx_env_path",
|
|
36
|
-
"xx_file",
|
|
37
|
-
"xx_format_codes",
|
|
38
|
-
"xx_json",
|
|
39
|
-
"xx_path",
|
|
40
|
-
"xx_regex",
|
|
41
|
-
"xx_string",
|
|
42
|
-
"xx_system",
|
|
9
|
+
"_consts_", "xx_code", "xx_color", "xx_console", "xx_data", "xx_env_path", "xx_file", "xx_format_codes", "xx_json",
|
|
10
|
+
"xx_path", "xx_regex", "xx_string", "xx_system"
|
|
43
11
|
]
|
|
44
12
|
|
|
45
13
|
from ._consts_ import *
|
xulbux/_cli_.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from . import __version__
|
|
2
1
|
from ._consts_ import COLOR
|
|
2
|
+
from . import __version__
|
|
3
3
|
from .xx_format_codes import FormatCodes
|
|
4
4
|
from .xx_console import Console
|
|
5
5
|
|
|
@@ -7,11 +7,13 @@ 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
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
10
|
+
"class": COLOR.tangerine,
|
|
11
|
+
"const": COLOR.red,
|
|
12
|
+
"func": COLOR.cyan,
|
|
13
|
+
"import": COLOR.neongreen,
|
|
14
|
+
"lib": COLOR.orange,
|
|
14
15
|
"punctuators": COLOR.darkgray,
|
|
16
|
+
"code_border": COLOR.gray,
|
|
15
17
|
}
|
|
16
18
|
FormatCodes.print(
|
|
17
19
|
rf""" [_|b|#7075FF] __ __
|
|
@@ -22,29 +24,20 @@ def help_command():
|
|
|
22
24
|
|
|
23
25
|
[i|{COLOR.coral}]A TON OF COOL FUNCTIONS, YOU NEED![*]
|
|
24
26
|
|
|
25
|
-
[b|#
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
[dim](•) SYSTEM ACTIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]System[*]
|
|
40
|
-
[dim](•) MANAGE THE ENV PATH VAR [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]EnvPath[*]
|
|
41
|
-
[dim](•) CONSOLE LOG AND ACTIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Console[*]
|
|
42
|
-
[dim](•) EASY PRETTY PRINTING [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]FormatCodes[*]
|
|
43
|
-
[dim](•) WORKING WITH COLORS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Color[*]
|
|
44
|
-
[dim](•) DATA OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Data[*]
|
|
45
|
-
[dim](•) STRING OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]String[*]
|
|
46
|
-
[dim](•) CODE STRING OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Code[*]
|
|
47
|
-
[dim](•) REGEX PATTERN TEMPLATES [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Regex[*]
|
|
27
|
+
[b|#FCFCFF]Usage:[*]
|
|
28
|
+
[dim|{color['code_border']}](╭────────────────────────────────────────────────────╮)
|
|
29
|
+
[dim|{color['code_border']}](│) [{color['punctuators']}]# CONSTANTS[*] [dim|{color['code_border']}](│)
|
|
30
|
+
[dim|{color['code_border']}](│) [{color['import']}]from [{color['lib']}]xulbux [{color['import']}]import [{color['const']}]COLOR[{color['punctuators']}], [{color['const']}]CHARS[{color['punctuators']}], [{color['const']}]ANSI[*] [dim|{color['code_border']}](│)
|
|
31
|
+
[dim|{color['code_border']}](│) [{color['punctuators']}]# Classes[*] [dim|{color['code_border']}](│)
|
|
32
|
+
[dim|{color['code_border']}](│) [{color['import']}]from [{color['lib']}]xulbux [{color['import']}]import [{color['class']}]Code[{color['punctuators']}], [{color['class']}]Color[{color['punctuators']}], [{color['class']}]Console[{color['punctuators']}], ...[*] [dim|{color['code_border']}](│)
|
|
33
|
+
[dim|{color['code_border']}](│) [{color['punctuators']}]# types[*] [dim|{color['code_border']}](│)
|
|
34
|
+
[dim|{color['code_border']}](│) [{color['import']}]from [{color['lib']}]xulbux [{color['import']}]import [{color['func']}]rgba[{color['punctuators']}], [{color['func']}]hsla[{color['punctuators']}], [{color['func']}]hexa[*] [dim|{color['code_border']}](│)
|
|
35
|
+
[dim|{color['code_border']}](╰────────────────────────────────────────────────────╯)
|
|
36
|
+
[b|#FCFCFF]Documentation:[*]
|
|
37
|
+
[dim|{color['code_border']}](╭────────────────────────────────────────────────────╮)
|
|
38
|
+
[dim|{color['code_border']}](│) [#DADADD]For more information see the GitHub page. [dim|{color['code_border']}](│)
|
|
39
|
+
[dim|{color['code_border']}](│) [u|#8085FF](https://github.com/XulbuX/PythonLibraryXulbuX/wiki) [dim|{color['code_border']}](│)
|
|
40
|
+
[dim|{color['code_border']}](╰────────────────────────────────────────────────────╯)
|
|
48
41
|
[_]
|
|
49
42
|
[dim](Press any key to exit...)
|
|
50
43
|
""",
|
xulbux/_consts_.py
CHANGED
xulbux/xx_code.py
CHANGED
|
@@ -21,13 +21,14 @@ class Code:
|
|
|
21
21
|
non_zero_indents = [i for i in indents if i > 0]
|
|
22
22
|
return min(non_zero_indents) if non_zero_indents else 0
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
@staticmethod
|
|
25
|
+
def change_tab_size(code: str, new_tab_size: int, remove_empty_lines: bool = False) -> str:
|
|
25
26
|
"""Replaces all tabs with `new_tab_size` spaces.\n
|
|
26
27
|
----------------------------------------------------------------------------------
|
|
27
28
|
If `remove_empty_lines` is `True`, empty lines will be removed in the process."""
|
|
28
29
|
code_lines = String.get_lines(code, remove_empty_lines=True)
|
|
29
30
|
lines = code_lines if remove_empty_lines else String.get_lines(code)
|
|
30
|
-
tab_spaces =
|
|
31
|
+
tab_spaces = Code.get_tab_spaces(code)
|
|
31
32
|
if (tab_spaces == new_tab_size) or tab_spaces == 0:
|
|
32
33
|
if remove_empty_lines:
|
|
33
34
|
return "\n".join(code_lines)
|
|
@@ -49,51 +50,66 @@ class Code:
|
|
|
49
50
|
nested_calls = _rx.findall(r"(?i)" + Regex.func_call(), func_attrs)
|
|
50
51
|
if nested_calls:
|
|
51
52
|
nested_func_calls.extend(nested_calls)
|
|
52
|
-
return Data.remove_duplicates(funcs + nested_func_calls)
|
|
53
|
+
return list(Data.remove_duplicates(funcs + nested_func_calls))
|
|
53
54
|
|
|
54
55
|
@staticmethod
|
|
55
56
|
def is_js(code: str, funcs: list = ["__", "$t", "$lang"]) -> bool:
|
|
56
57
|
"""Will check if the code is very likely to be JavaScript."""
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
58
|
+
if not code or len(code.strip()) < 3:
|
|
59
|
+
return False
|
|
60
|
+
for func in funcs:
|
|
61
|
+
if _rx.match(r"^[\s\n]*" + _rx.escape(func) + r"\([^\)]*\)[\s\n]*$", code):
|
|
62
|
+
return True
|
|
63
|
+
direct_js_patterns = [
|
|
64
|
+
r"^[\s\n]*\$\(['\"][^'\"]+['\"]\)\.[\w]+\([^\)]*\);?[\s\n]*$", # jQuery calls
|
|
65
|
+
r"^[\s\n]*\$\.[a-zA-Z]\w*\([^\)]*\);?[\s\n]*$", # $.ajax(), etc.
|
|
66
|
+
r"^[\s\n]*\(\s*function\s*\(\)\s*\{.*\}\s*\)\(\);?[\s\n]*$", # IIFE
|
|
67
|
+
r"^[\s\n]*document\.[a-zA-Z]\w*\([^\)]*\);?[\s\n]*$", # document.getElementById()
|
|
68
|
+
r"^[\s\n]*window\.[a-zA-Z]\w*\([^\)]*\);?[\s\n]*$", # window.alert()
|
|
69
|
+
r"^[\s\n]*console\.[a-zA-Z]\w*\([^\)]*\);?[\s\n]*$", # console.log()
|
|
70
|
+
]
|
|
71
|
+
for pattern in direct_js_patterns:
|
|
72
|
+
if _rx.match(pattern, code):
|
|
73
|
+
return True
|
|
74
|
+
arrow_function_patterns = [
|
|
75
|
+
r"^[\s\n]*\b[\w_]+\s*=\s*\([^\)]*\)\s*=>\s*[^;{]*[;]?[\s\n]*$", # const x = (y) => y*2;
|
|
76
|
+
r"^[\s\n]*\b[\w_]+\s*=\s*[\w_]+\s*=>\s*[^;{]*[;]?[\s\n]*$", # const x = y => y*2;
|
|
77
|
+
r"^[\s\n]*\(\s*[\w_,\s]+\s*\)\s*=>\s*[^;{]*[;]?[\s\n]*$", # (x) => x*2
|
|
78
|
+
r"^[\s\n]*[\w_]+\s*=>\s*[^;{]*[;]?[\s\n]*$", # x => x*2
|
|
79
|
+
]
|
|
80
|
+
for pattern in arrow_function_patterns:
|
|
81
|
+
if _rx.match(pattern, code):
|
|
82
|
+
return True
|
|
83
|
+
funcs_pattern = r"(" + "|".join(_rx.escape(f) for f in funcs) + r")" + Regex.brackets("()")
|
|
84
|
+
js_indicators = [(r"\b(var|let|const)\s+[\w_$]+", 2), # JS variable declarations
|
|
85
|
+
(r"\$[\w_$]+\s*=", 2), # jQuery-style variables
|
|
86
|
+
(r"\$[\w_$]+\s*\(", 2), # jQuery function calls
|
|
87
|
+
(r"\bfunction\s*[\w_$]*\s*\(", 2), # Function declarations
|
|
88
|
+
(r"[\w_$]+\s*=\s*function\s*\(", 2), # Function assignments
|
|
89
|
+
(r"\b[\w_$]+\s*=>\s*[\{\(]", 2), # Arrow functions
|
|
90
|
+
(r"\(function\s*\(\)\s*\{", 2), # IIFE pattern
|
|
91
|
+
(funcs_pattern, 2), # Custom predefined functions
|
|
92
|
+
(r"\b(true|false|null|undefined)\b", 1), # JS literals
|
|
93
|
+
(r"===|!==|\+\+|--|\|\||&&", 1.5), # JS-specific operators
|
|
94
|
+
(r"\bnew\s+[\w_$]+\s*\(", 1.5), # Object instantiation with new
|
|
95
|
+
(r"\b(document|window|console|Math|Array|Object|String|Number)\.", 2), # JS objects
|
|
96
|
+
(r"\basync\s+function|\bawait\b", 2), # Async/await
|
|
97
|
+
(r"\b(if|for|while|switch)\s*\([^)]*\)\s*\{", 1), # Control structures with braces
|
|
98
|
+
(r"\btry\s*\{[^}]*\}\s*catch\s*\(", 1.5), # Try-catch
|
|
99
|
+
(r";[\s\n]*$", 0.5), # Semicolon line endings
|
|
100
|
+
]
|
|
101
|
+
js_score = 0
|
|
102
|
+
line_endings = [line.strip() for line in code.splitlines() if line.strip()]
|
|
103
|
+
semicolon_endings = sum(1 for line in line_endings if line.endswith(';'))
|
|
104
|
+
if semicolon_endings >= 1:
|
|
105
|
+
js_score += min(semicolon_endings, 2)
|
|
106
|
+
opening_braces = code.count('{')
|
|
107
|
+
closing_braces = code.count('}')
|
|
108
|
+
if opening_braces > 0 and opening_braces == closing_braces:
|
|
109
|
+
js_score += 1
|
|
110
|
+
for pattern, score in js_indicators:
|
|
111
|
+
regex = _rx.compile(pattern, _rx.IGNORECASE)
|
|
112
|
+
matches = regex.findall(code)
|
|
113
|
+
if matches:
|
|
114
|
+
js_score += len(matches) * score
|
|
115
|
+
return js_score >= 2
|