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 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
- "xx_console",
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
- "lib": COLOR.ice,
11
- "import": COLOR.red,
12
- "class": COLOR.lavender,
13
- "types": COLOR.lightblue,
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|#75A2FF]Usage:[*]
26
- [{color['punctuators']}]# GENERAL LIBRARY[*]
27
- [{color['import']}]import [{color['lib']}]xulbux [{color['import']}]as [{color['lib']}]xx[*]
28
- [{color['punctuators']}]# CUSTOM TYPES[*]
29
- [{color['import']}]from [{color['lib']}]xulbux [{color['import']}]import [{color['lib']}]rgba[{color['punctuators']}], [{color['lib']}]hsla[{color['punctuators']}], [{color['lib']}]hexa[*]
30
-
31
- [b|#75A2FF]Includes:[*]
32
- [dim]() CUSTOM TYPES:
33
- [dim](•) [{color['class']}]rgba[{color['punctuators']}]/([i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]float[_|{color['punctuators']}])[*]
34
- [dim](•) [{color['class']}]hsla[{color['punctuators']}]/([i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]float[_|{color['punctuators']}])[*]
35
- [dim](•) [{color['class']}]hexa[{color['punctuators']}]/([i|{color['types']}]str[_|{color['punctuators']}]|[i|{color['types']}]int[_|{color['punctuators']}])[*]
36
- [dim](•) PATH OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Path[*]
37
- [dim](•) FILE OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]File[*]
38
- [dim](•) JSON FILE OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Json[*]
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
@@ -26,6 +26,7 @@ class COLOR:
26
26
  yellow = "#FFD260"
27
27
  lime = "#C9F16E"
28
28
  green = "#7EE787"
29
+ neongreen = "#4CFF85"
29
30
  teal = "#50EAAF"
30
31
  cyan = "#3EDEE6"
31
32
  ice = "#77DBEF"
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
- def change_tab_size(self, code: str, new_tab_size: int, remove_empty_lines: bool = False) -> str:
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 = self.get_tab_spaces(code)
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
- funcs = "|".join(funcs)
58
- js_pattern = _rx.compile(
59
- Regex.outside_strings(
60
- r"""^(?:
61
- (\$[\w_]+)\s* # JQUERY-STYLE VARIABLES
62
- |(\$[\w_]+\s*\() # JQUERY-STYLE FUNCTION CALLS
63
- |((""" + funcs + r")" + Regex.brackets("()") + r"""\s*) # PREDEFINED FUNCTION CALLS
64
- |(\bfunction\s*\() # FUNCTION DECLARATIONS
65
- |(\b(var|let|const)\s+[\w_]+\s*=) # VARIABLE DECLARATIONS
66
- |(\b(if|for|while|switch)\s*\() # CONTROL STRUCTURES
67
- |(\b(return|throw)\s+) # RETURN OR THROW STATEMENTS
68
- |(\bnew\s+[\w_]+\() # OBJECT INSTANTIATION
69
- |(\b[\w_]+\s*=>\s*{) # ARROW FUNCTIONS
70
- |(\b(true|false|null|undefined)\b) # JAVASCRIPT LITERALS
71
- |(\b(document|window|console)\.) # BROWSER OBJECTS
72
- |(\b[\w_]+\.(forEach|map|filter|reduce)\() # ARRAY METHODS
73
- |(/[^/\n\r]*?/[gimsuy]*) # REGULAR EXPRESSIONS
74
- |(===|!==|\+\+|--|\|\||&&) # JAVASCRIPT-SPECIFIC OPERATORS
75
- |(\bclass\s+[\w_]+) # CLASS DECLARATIONS
76
- |(\bimport\s+.*?from\s+) # IMPORT STATEMENTS
77
- |(\bexport\s+(default\s+)?) # EXPORT STATEMENTS
78
- |(\basync\s+function) # ASYNC FUNCTIONS
79
- |(\bawait\s+) # AWAIT KEYWORD
80
- |(\btry\s*{) # TRY-CATCH BLOCKS
81
- |(\bcatch\s*\()
82
- |(\bfinally\s*{)
83
- |(\byield\s+) # GENERATOR FUNCTIONS
84
- |(\[.*?\]\s*=) # DESTRUCTURING ASSIGNMENT
85
- |(\.\.\.) # SPREAD OPERATOR
86
- |(==|!=|>=|<=|>|<) # COMPARISON OPERATORS
87
- |(\+=|-=|\*=|/=|%=|\*\*=) # COMPOUND ASSIGNMENT OPERATORS
88
- |(\+|-|\*|/|%|\*\*) # ARITHMETIC OPERATORS
89
- |(&|\||\^|~|<<|>>|>>>) # BITWISE OPERATORS
90
- |(\?|:) # TERNARY OPERATOR
91
- |(\bin\b) # IN OPERATOR
92
- |(\binstanceof\b) # INSTANCEOF OPERATOR
93
- |(\bdelete\b) # DELETE OPERATOR
94
- |(\btypeof\b) # TYPEOF OPERATOR
95
- |(\bvoid\b) # VOID OPERATOR
96
- )[\s\S]*$"""
97
- ), _rx.VERBOSE | _rx.IGNORECASE
98
- )
99
- return bool(js_pattern.fullmatch(code))
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