xulbux 1.6.5__py3-none-any.whl → 1.6.6__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/xx_regex.py CHANGED
@@ -1,12 +1,5 @@
1
1
  """
2
- Really long regex code presets:
3
- `quotes` match everything inside quotes
4
- `brackets` match everything inside brackets
5
- `outside_strings` match the pattern but not inside strings
6
- `all_except` match everything except a certain pattern
7
- `func_call` match a function call
8
- `rgba_str` match an RGBA color
9
- `hsla_str` match a HSLA color
2
+ Very useful and complicated (generated) regex patterns.
10
3
  """
11
4
 
12
5
  import regex as _rx
@@ -27,24 +20,34 @@ class Regex:
27
20
  return r'(?P<quote>[\'"])(?P<string>(?:\\.|(?!\g<quote>).)*?)\g<quote>'
28
21
 
29
22
  @staticmethod
30
- def brackets(bracket1: str = "(", bracket2: str = ")", is_group: bool = False, ignore_in_strings: bool = True) -> str:
23
+ def brackets(
24
+ bracket1: str = "(",
25
+ bracket2: str = ")",
26
+ is_group: bool = False,
27
+ strip_spaces: bool = True,
28
+ ignore_in_strings: bool = True,
29
+ ) -> str:
31
30
  """Matches everything inside brackets, including other nested brackets.\n
32
31
  --------------------------------------------------------------------------------
33
32
  If `is_group` is true, you will be able to reference the matched content as a
34
33
  group (e.g. `match.group(…)` or `r'\\…'`).
34
+ If `strip_spaces` is true, it will ignore spaces around the content inside the
35
+ brackets.
35
36
  If `ignore_in_strings` is true and a bracket is inside a string (e.g. `'...'`
36
37
  or `"..."`), it will not be counted as the matching closing bracket.\n
37
38
  --------------------------------------------------------------------------------
38
39
  Attention: Requires non standard library `regex` not standard library `re`!"""
39
- g, b1, b2 = (
40
+ g, b1, b2, s1, s2 = (
40
41
  "" if is_group else "?:",
41
42
  _rx.escape(bracket1) if len(bracket1) == 1 else bracket1,
42
43
  _rx.escape(bracket2) if len(bracket2) == 1 else bracket2,
44
+ r"\s*" if strip_spaces else "",
45
+ "" if strip_spaces else r"\s*",
43
46
  )
44
47
  if ignore_in_strings:
45
- return rf'{b1}\s*({g}(?:[^{b1}{b2}"\']|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|{b1}(?:[^{b1}{b2}"\']|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|(?R))*{b2})*)\s*{b2}'
48
+ return rf'{b1}{s1}({g}{s2}(?:[^{b1}{b2}"\']|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|{b1}(?:[^{b1}{b2}"\']|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|(?R))*{b2})*{s2}){s1}{b2}'
46
49
  else:
47
- return rf"{b1}\s*({g}(?:[^{b1}{b2}]|{b1}(?:[^{b1}{b2}]|(?R))*{b2})*)\s*{b2}"
50
+ return rf"{b1}{s1}({g}{s2}(?:[^{b1}{b2}]|{b1}(?:[^{b1}{b2}]|(?R))*{b2})*{s2}){s1}{b2}"
48
51
 
49
52
  @staticmethod
50
53
  def outside_strings(pattern: str = r".*") -> str:
@@ -109,9 +112,7 @@ class Regex:
109
112
  rf"""(?ix)
110
113
  (?:rgb|rgba)?\s*(?:\(?\s*{rgb_part}
111
114
  (?:(?:\s*{fix_sep}\s*)((?:0*(?:0?\.[0-9]+|1\.0+|[0-9]+\.[0-9]+|[0-9]+))))?
112
- \s*\)?)"""
113
- if allow_alpha
114
- else rf"(?ix)(?:rgb|rgba)?\s*(?:\(?\s*{rgb_part}\s*\)?)"
115
+ \s*\)?)""" if allow_alpha else rf"(?ix)(?:rgb|rgba)?\s*(?:\(?\s*{rgb_part}\s*\)?)"
115
116
  )
116
117
 
117
118
  @staticmethod
@@ -144,9 +145,7 @@ class Regex:
144
145
  rf"""(?ix)
145
146
  (?:hsl|hsla)?\s*(?:\(?\s*{hsl_part}
146
147
  (?:(?:\s*{fix_sep}\s*)((?:0*(?:0?\.[0-9]+|1\.0+|[0-9]+\.[0-9]+|[0-9]+))))?
147
- \s*\)?)"""
148
- if allow_alpha
149
- else rf"(?ix)(?:hsl|hsla)?\s*(?:\(?\s*{hsl_part}\s*\)?)"
148
+ \s*\)?)""" if allow_alpha else rf"(?ix)(?:hsl|hsla)?\s*(?:\(?\s*{hsl_part}\s*\)?)"
150
149
  )
151
150
 
152
151
  @staticmethod
@@ -162,6 +161,5 @@ class Regex:
162
161
  every channel from 0-9 and A-F (case insensitive)"""
163
162
  return (
164
163
  r"(?i)^(?:#|0x)?[0-9A-F]{8}|[0-9A-F]{6}|[0-9A-F]{4}|[0-9A-F]{3}$"
165
- if allow_alpha
166
- else r"(?i)^(?:#|0x)?[0-9A-F]{6}|[0-9A-F]{3}$"
164
+ if allow_alpha else r"(?i)^(?:#|0x)?[0-9A-F]{6}|[0-9A-F]{3}$"
167
165
  )
xulbux/xx_string.py CHANGED
@@ -1,3 +1,5 @@
1
+ import json as _json
2
+ import ast as _ast
1
3
  import re as _re
2
4
 
3
5
 
@@ -5,73 +7,25 @@ class String:
5
7
 
6
8
  @staticmethod
7
9
  def to_type(string: str) -> any:
8
- """Will convert a string to the found type."""
9
- string = string.strip() # Clean up whitespace
10
- # BOOLEAN
11
- if _re.match(r"(?i)^(true|false)$", string):
12
- return string.lower() == "true"
13
- # NONE
14
- elif _re.match(r"(?i)^(none|null|undefined)$", string):
15
- return None
16
- # INTEGER
17
- elif _re.match(r"^-?\d+$", string):
18
- return int(string)
19
- # FLOAT
20
- elif _re.match(r"^-?\d+\.\d+$", string):
21
- return float(string)
22
- # COMPLEX
23
- elif _re.match(r"^(-?\d+(\.\d+)?[+-]\d+(\.\d+)?j)$", string):
24
- return complex(string)
25
- # QUOTED STRING
26
- elif _re.match(r'^["\'](.*)["\']$', string):
27
- return string[1:-1]
28
- # BYTES
29
- elif _re.match(r"^b['\"](.*)['\"]$", string):
30
- return bytes(string[2:-1], "utf-8")
31
- # LIST
32
- elif _re.match(r"^\[(.*)\]$", string):
33
- return [
34
- String.to_type(item.strip()) for item in _re.findall(r"(?:[^,\[\]]+|\[.*?\]|\(.*?\)|\{.*?\})+", string[1:-1])
35
- ]
36
- # TUPLE
37
- elif _re.match(r"^\((.*)\)$", string):
38
- return tuple(
39
- String.to_type(item.strip()) for item in _re.findall(r"(?:[^,\(\)]+|\[.*?\]|\(.*?\)|\{.*?\})+", string[1:-1])
40
- )
41
- # DICTIONARY
42
- elif _re.match(r"^\{(.*)\}$", string) and ":" in string:
43
- return {
44
- String.to_type(k.strip()): String.to_type(v.strip())
45
- for k, v in _re.findall(
46
- r"((?:[^:,{}]+|\[.*?\]|\(.*?\)|\{.*?\})+)\s*:\s*((?:[^:,{}]+|\[.*?\]|\(.*?\)|\{.*?\})+)", string[1:-1]
47
- )
48
- }
49
- # SET
50
- elif _re.match(r"^\{(.*?)\}$", string):
51
- return {
52
- String.to_type(item.strip()) for item in _re.findall(r"(?:[^,{}]+|\[.*?\]|\(.*?\)|\{.*?\})+", string[1:-1])
53
- }
54
- # RETURN AS IS (str)
55
- return string
10
+ """Will convert a string to the found type, including complex nested structures."""
11
+ string = string.strip()
12
+ try:
13
+ return _ast.literal_eval(string)
14
+ except (ValueError, SyntaxError):
15
+ try:
16
+ return _json.loads(string)
17
+ except _json.JSONDecodeError:
18
+ return string
56
19
 
57
20
  @staticmethod
58
21
  def normalize_spaces(string: str, tab_spaces: int = 4) -> str:
59
22
  """Replaces all special space characters with normal spaces.
60
23
  Also replaces tab characters with `tab_spaces` spaces."""
61
- return (
62
- string.replace("\t", " " * tab_spaces)
63
- .replace("\u2000", " ")
64
- .replace("\u2001", " ")
65
- .replace("\u2002", " ")
66
- .replace("\u2003", " ")
67
- .replace("\u2004", " ")
68
- .replace("\u2005", " ")
69
- .replace("\u2006", " ")
70
- .replace("\u2007", " ")
71
- .replace("\u2008", " ")
72
- .replace("\u2009", " ")
73
- .replace("\u200A", " ")
74
- )
24
+ return ( # YAPF: disable
25
+ string.replace("\t", " " * tab_spaces).replace("\u2000", " ").replace("\u2001", " ").replace("\u2002", " ")
26
+ .replace("\u2003", " ").replace("\u2004", " ").replace("\u2005", " ").replace("\u2006", " ")
27
+ .replace("\u2007", " ").replace("\u2008", " ").replace("\u2009", " ").replace("\u200A", " ")
28
+ ) # YAPF: enable
75
29
 
76
30
  @staticmethod
77
31
  def escape(string: str, str_quotes: str = '"') -> str:
@@ -80,15 +34,10 @@ class String:
80
34
  `str_quotes` can be either `"` or `'` and should match the quotes, the string will be put
81
35
  inside of. So if your string will be `"string"`, you should pass `"` to the parameter
82
36
  `str_quotes`. That way, if the string includes the same quotes, they will be escaped."""
83
- string = (
84
- string.replace("\\", r"\\")
85
- .replace("\n", r"\n")
86
- .replace("\r", r"\r")
87
- .replace("\t", r"\t")
88
- .replace("\b", r"\b")
89
- .replace("\f", r"\f")
90
- .replace("\a", r"\a")
91
- )
37
+ string = ( # YAPF: disable
38
+ string.replace("\\", r"\\").replace("\n", r"\n").replace("\r", r"\r").replace("\t", r"\t")
39
+ .replace("\b", r"\b").replace("\f", r"\f").replace("\a", r"\a")
40
+ ) # YAPF: enable
92
41
  if str_quotes == '"':
93
42
  string = string.replace(r"\\'", "'").replace(r'"', r"\"")
94
43
  elif str_quotes == "'":
@@ -114,10 +63,8 @@ class String:
114
63
  @staticmethod
115
64
  def decompose(case_string: str, seps: str = "-_", lower_all: bool = True) -> list[str]:
116
65
  """Will decompose the string (any type of casing, also mixed) into parts."""
117
- return [
118
- (part.lower() if lower_all else part)
119
- for part in _re.split(rf"(?<=[a-z])(?=[A-Z])|[{_re.escape(seps)}]", case_string)
120
- ]
66
+ return [(part.lower() if lower_all else part)
67
+ for part in _re.split(rf"(?<=[a-z])(?=[A-Z])|[{_re.escape(seps)}]", case_string)]
121
68
 
122
69
  @staticmethod
123
70
  def to_camel_case(string: str, upper: bool = True) -> str:
@@ -155,4 +102,4 @@ class String:
155
102
  @staticmethod
156
103
  def split_count(string: str, count: int) -> list[str]:
157
104
  """Will split the string every `count` characters."""
158
- return [string[i : i + count] for i in range(0, len(string), count)]
105
+ return [string[i:i + count] for i in range(0, len(string), count)]
xulbux/xx_system.py CHANGED
@@ -1,3 +1,4 @@
1
+ from typing import Optional
1
2
  import subprocess as _subprocess
2
3
  import platform as _platform
3
4
  import ctypes as _ctypes
@@ -20,17 +21,12 @@ class System:
20
21
  return _ctypes.windll.shell32.IsUserAnAdmin() != 0
21
22
  elif _os.name == "posix":
22
23
  return _os.geteuid() == 0
23
- except:
24
+ except Exception:
24
25
  pass
25
26
  return False
26
27
 
27
28
  @staticmethod
28
- def restart(
29
- prompt: object = None,
30
- wait: int = 0,
31
- continue_program: bool = False,
32
- force: bool = False,
33
- ) -> None:
29
+ def restart(prompt: object = None, wait: int = 0, continue_program: bool = False, force: bool = False) -> None:
34
30
  """Starts a system restart:
35
31
  - `prompt` is the message to be displayed in the systems restart notification.
36
32
  - `wait` is the time to wait until restarting in seconds.
@@ -70,11 +66,7 @@ class System:
70
66
  raise NotImplementedError(f"Restart not implemented for `{system}`")
71
67
 
72
68
  @staticmethod
73
- def check_libs(
74
- lib_names: list[str],
75
- install_missing: bool = False,
76
- confirm_install: bool = True,
77
- ) -> None | list[str]:
69
+ def check_libs(lib_names: list[str], install_missing: bool = False, confirm_install: bool = True) -> Optional[list[str]]:
78
70
  """Checks if the given list of libraries are installed. If not:
79
71
  - If `install_missing` is `False` the missing libraries will be returned as a list.
80
72
  - If `install_missing` is `True` the missing libraries will be installed.
@@ -102,7 +94,7 @@ class System:
102
94
  return missing
103
95
 
104
96
  @staticmethod
105
- def elevate(win_title: str | None = None, args: list | None = None) -> bool:
97
+ def elevate(win_title: Optional[str] = None, args: Optional[list] = None) -> bool:
106
98
  """Attempts to start a new process with elevated privileges.\n
107
99
  ---------------------------------------------------------------------------------
108
100
  The param `win_title` is window the title of the elevated process.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: xulbux
3
- Version: 1.6.5
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
@@ -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,6 +53,7 @@ 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
 
@@ -0,0 +1,21 @@
1
+ xulbux/__init__.py,sha256=kGUOl7SiyAMqKsEZfZODjJILWaFVVRnzAkT5WrwmHMQ,1654
2
+ xulbux/_cli_.py,sha256=I1TieHnX60mlRvMaTQnon-VRuf_70dkP7sOU1aHthQY,3470
3
+ xulbux/_consts_.py,sha256=aQyWSJ5_Spqot1HHWKbYj1j-6YSakIqG89Olv7rp7Ms,4886
4
+ xulbux/xx_code.py,sha256=dY2HRXIDXHN3KTzzUkQVBacFDExNVwH8flREshwi4vk,5288
5
+ xulbux/xx_color.py,sha256=nwcd5_4JIRfZ99JqbCXMl4RWpic_-M361AA5zEa9Nuw,44846
6
+ xulbux/xx_console.py,sha256=pwB1gLuwTj9V2FhcK-kNTfK7eK3Mb-fbsD59Cua-XTM,20078
7
+ xulbux/xx_data.py,sha256=fkJKArU7TTmXTk90vG_s4BHIor6NRqUP_gqypyv3v9U,30254
8
+ xulbux/xx_env_path.py,sha256=e5r47g-dLIo_J9RM9teqLM1rTzNsI0w9U0xjjcK6nro,4321
9
+ xulbux/xx_file.py,sha256=MGGrPDyvgVQJrdcRSGE_jiB_aQz6zo5I0m6_5pKYIo8,3123
10
+ xulbux/xx_format_codes.py,sha256=abR9TWtnBLF0L08oyRjDYXx9VCtun9kjGVPmkv44emU,20359
11
+ xulbux/xx_json.py,sha256=dw2AiqMErdjW0ot4pICDBdTL6j03IrYJWJz-Lw21d4Q,5149
12
+ xulbux/xx_path.py,sha256=KjSurQ9SHqcdhyTo1vzZn2qGXaQr3T1eDr-E_PVdyXo,4537
13
+ xulbux/xx_regex.py,sha256=gvnDel8xVmf11kvhc0iIjSj1dFW3OLnXNDlaJsUxXU4,7952
14
+ xulbux/xx_string.py,sha256=nJBXAVNknhTE9N_4yOyCVwSSIwOyHCRlZe_D7LOgrOY,5450
15
+ xulbux/xx_system.py,sha256=izDmmrh3o66drAp-LkqsA5AruAdHprq5p_CuseT1OJI,6399
16
+ xulbux-1.6.6.dist-info/LICENSE,sha256=6NflEcvzFEe8_JFVNCPVwZBwBhlLLd4vqQi8WiX_Xk4,1084
17
+ xulbux-1.6.6.dist-info/METADATA,sha256=s2U6Uel8qNsGjnL8Czi8nxzXcOy_sByZCSd_dLAg-w4,6979
18
+ xulbux-1.6.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
19
+ xulbux-1.6.6.dist-info/entry_points.txt,sha256=a3womfLIMZKnOFiyy-xnVb4g2qkZsHR5FbKKkljcGns,94
20
+ xulbux-1.6.6.dist-info/top_level.txt,sha256=FkK4EZajwfP36fnlrPaR98OrEvZpvdEOdW1T5zTj6og,7
21
+ xulbux-1.6.6.dist-info/RECORD,,
@@ -1,21 +0,0 @@
1
- xulbux/__init__.py,sha256=oLUyQ20jckO5yaen5i7y4ydoDb3WovCw-1PDAXtfEzg,1654
2
- xulbux/_cli_.py,sha256=U25ZrtpQgpKXtvOSTBBbh7-AJ_WTeZ95A66DQARAqzo,3558
3
- xulbux/_consts_.py,sha256=I-dAF5_0NXrHXUZLMylOKFBiJRc3qMKIFf7wMpaNzeI,4591
4
- xulbux/xx_code.py,sha256=yBP5WxCxNxjBiS6nVAmUBJpD0hX6fgnh5RWq-NmrnaY,5222
5
- xulbux/xx_color.py,sha256=kqlU9hyO9BFy7uiMJjkNiQXW8-hPrAwZokJ8gQMbo80,45298
6
- xulbux/xx_console.py,sha256=IJ2oD9MMUyLzBQCbMViZd_2mV33ERqFX9DXEAOX4e8g,16974
7
- xulbux/xx_data.py,sha256=MqTt_hpBUdgaf-DroVXp5euXM1ApeTiW2ognCFFitC4,25844
8
- xulbux/xx_env_path.py,sha256=iv3Jw0TsNDbbL_NySnazvIP9Iv9swymhiJIr2B3EG8k,4388
9
- xulbux/xx_file.py,sha256=MGGrPDyvgVQJrdcRSGE_jiB_aQz6zo5I0m6_5pKYIo8,3123
10
- xulbux/xx_format_codes.py,sha256=pL4BpV74YOYs8yltMrWTjGQ3x8vtELSbXEPhx6EWV4s,20380
11
- xulbux/xx_json.py,sha256=q60lOj8Xg8c4L9cBu6SBZdJzFC7QbjDfFwcKKzBKj5w,5173
12
- xulbux/xx_path.py,sha256=_xkH9cowPdi3nHw2q_TvN_i_5oG6GJut-QwPBLxnrAQ,4519
13
- xulbux/xx_regex.py,sha256=S1-MIk2qG4vHdxuaHGhMe5PHfY1SF9kncg8iQ8HJgS4,8002
14
- xulbux/xx_string.py,sha256=de6rwINc_2sIDI35POxIzu2REU4Oc9Oau13Pz2sUgkA,7208
15
- xulbux/xx_system.py,sha256=M3VGU3Tf3nDU59DjIJgDXJOqNB80Vr0wf15Vcnb5UCo,6430
16
- xulbux-1.6.5.dist-info/LICENSE,sha256=6NflEcvzFEe8_JFVNCPVwZBwBhlLLd4vqQi8WiX_Xk4,1084
17
- xulbux-1.6.5.dist-info/METADATA,sha256=yo1jnPqizUqaC3UCKsHU69qPIxInJS5Ex6iH4m30CN4,6884
18
- xulbux-1.6.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
19
- xulbux-1.6.5.dist-info/entry_points.txt,sha256=a3womfLIMZKnOFiyy-xnVb4g2qkZsHR5FbKKkljcGns,94
20
- xulbux-1.6.5.dist-info/top_level.txt,sha256=FkK4EZajwfP36fnlrPaR98OrEvZpvdEOdW1T5zTj6og,7
21
- xulbux-1.6.5.dist-info/RECORD,,
File without changes