click-extended 1.0.5__py3-none-any.whl → 1.0.7__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.
@@ -3,6 +3,7 @@ Child validation node module for nodes that can
3
3
  act as both child and validation nodes.
4
4
  """
5
5
 
6
+ import asyncio
6
7
  from abc import ABC
7
8
  from functools import wraps
8
9
  from typing import TYPE_CHECKING, Any, Callable, ParamSpec, TypeVar
@@ -88,8 +89,20 @@ class ChildValidationNode(ChildNode, ValidationNode, ABC):
88
89
  instance = cls(name=name, process_args=args, process_kwargs=kwargs)
89
90
  Tree.queue_child_validation(instance)
90
91
 
92
+ if asyncio.iscoroutinefunction(func):
93
+
94
+ @wraps(func)
95
+ async def async_wrapper(
96
+ *call_args: P.args, **call_kwargs: P.kwargs
97
+ ) -> T:
98
+ """Async wrapper that preserves the original function."""
99
+ return await func(*call_args, **call_kwargs) # type: ignore
100
+
101
+ return async_wrapper # type: ignore
102
+
91
103
  @wraps(func)
92
104
  def wrapper(*call_args: P.args, **call_kwargs: P.kwargs) -> T:
105
+ """Wrapper that preserves the original function."""
93
106
  return func(*call_args, **call_kwargs)
94
107
 
95
108
  return wrapper
@@ -1,5 +1,6 @@
1
1
  """ValidationNode class for global validation logic."""
2
2
 
3
+ import asyncio
3
4
  from abc import ABC
4
5
  from functools import wraps
5
6
  from typing import TYPE_CHECKING, Any, Callable, ParamSpec, TypeVar
@@ -111,6 +112,18 @@ class ValidationNode(Node, ABC):
111
112
  instance = cls(name=name, process_args=args, process_kwargs=kwargs)
112
113
  Tree.queue_validation(instance)
113
114
 
115
+ if asyncio.iscoroutinefunction(func):
116
+
117
+ @wraps(func)
118
+ async def async_wrapper(
119
+ *call_args: P.args,
120
+ **call_kwargs: P.kwargs,
121
+ ) -> T:
122
+ """Async wrapper that preserves the original function."""
123
+ return await func(*call_args, **call_kwargs) # type: ignore
124
+
125
+ return async_wrapper # type: ignore
126
+
114
127
  @wraps(func)
115
128
  def wrapper(*call_args: P.args, **call_kwargs: P.kwargs) -> T:
116
129
  """Wrapper that preserves the original function."""
@@ -1,7 +1,7 @@
1
1
  """Check if a value matches a regex pattern."""
2
2
 
3
3
  import re
4
- from typing import Any
4
+ from typing import Any, Union
5
5
 
6
6
  from click_extended.core.nodes.child_node import ChildNode
7
7
  from click_extended.core.other.context import Context
@@ -18,17 +18,29 @@ class Regex(ChildNode):
18
18
  *args: Any,
19
19
  **kwargs: Any,
20
20
  ) -> Any:
21
- patterns = kwargs["patterns"]
21
+ patterns: tuple[Union[str, re.Pattern[str]], ...] = kwargs["patterns"]
22
+ flags: int = kwargs.get("flags", 0)
23
+
22
24
  for pattern in patterns:
23
- if re.fullmatch(pattern, value):
25
+ compiled_pattern: re.Pattern[str]
26
+ if isinstance(pattern, re.Pattern):
27
+ compiled_pattern = pattern
28
+ else:
29
+ compiled_pattern = re.compile(pattern, flags)
30
+
31
+ if compiled_pattern.fullmatch(value):
24
32
  return value
25
33
 
34
+ pattern_strs: list[str] = [
35
+ p.pattern if isinstance(p, re.Pattern) else p for p in patterns
36
+ ]
26
37
  raise ValueError(
27
- f"Value '{value}' does not match any of the patterns: {patterns}"
38
+ f"Value '{value}' does not match any "
39
+ + f"of the patterns: {pattern_strs}"
28
40
  )
29
41
 
30
42
 
31
- def regex(*patterns: str) -> Decorator:
43
+ def regex(*patterns: Union[str, re.Pattern[str]], flags: int = 0) -> Decorator:
32
44
  """
33
45
  Check if a value matches a regex pattern.
34
46
 
@@ -37,11 +49,17 @@ def regex(*patterns: str) -> Decorator:
37
49
  Supports: `str`
38
50
 
39
51
  Args:
40
- *patterns (str):
41
- The regex patterns to check against.
52
+ *patterns (Union[str, Pattern[str]]):
53
+ The regex patterns to check against. Can be strings or compiled
54
+ Pattern objects. If strings are provided, they will be compiled
55
+ with the specified flags.
56
+ flags (int):
57
+ Regex flags to use when compiling string patterns (e.g.,
58
+ re.IGNORECASE, re.MULTILINE). Ignored for pre-compiled patterns.
59
+ Default is 0 (no flags).
42
60
 
43
61
  Returns:
44
62
  Decorator:
45
63
  The decorated function.
46
64
  """
47
- return Regex.as_decorator(patterns=patterns)
65
+ return Regex.as_decorator(patterns=patterns, flags=flags)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: click_extended
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: An extension to Click with additional features like automatic async support, aliasing and a modular decorator system.
5
5
  Author-email: Marcus Fredriksson <marcus@marcusfredriksson.com>
6
6
  License: MIT License
@@ -17,11 +17,11 @@ click_extended/core/nodes/__init__.py,sha256=jSsKTiHPUpqXdk54cRXDotT0YMmVGezIIb3
17
17
  click_extended/core/nodes/_root_node.py,sha256=PitK6GT7LPYugxPFdVO6blG0-mZV9S2apUupgWCsYI0,43060
18
18
  click_extended/core/nodes/argument_node.py,sha256=gqG4HTDR40Xru_U_beKsbjVtLtwmPKfwwAUmcf5-1iQ,5284
19
19
  click_extended/core/nodes/child_node.py,sha256=yIuXmUzdXN0EToR9ohBRvHFBriSZ-xaLkv7P27PbTrA,17095
20
- click_extended/core/nodes/child_validation_node.py,sha256=p4ODRpW-Q-aQB0zlbNAeLahFAcuAaMLPtZl4r0ywmk0,3301
20
+ click_extended/core/nodes/child_validation_node.py,sha256=Xcqid9EL3pHVrgv_43zz-ZL4W4yFm0Esj2qkk9qhWMc,3807
21
21
  click_extended/core/nodes/node.py,sha256=Q5OgaSNhz1dAIcYNDQOaAS2eCdu9XMMyDA5lXfZbY4E,1602
22
22
  click_extended/core/nodes/option_node.py,sha256=fCYrnW846mz1aDyf9sTQAnuIYUGd5g6XyUN6aBMIWgE,7055
23
23
  click_extended/core/nodes/parent_node.py,sha256=x526r7XjfsUypsB1N-5aXjEbP2d06eLF30G6IszxV3w,7352
24
- click_extended/core/nodes/validation_node.py,sha256=9X_dBbr1BB-OYRxnGsM8CoKRbKT1MuQ29Injtf_Iu_E,4020
24
+ click_extended/core/nodes/validation_node.py,sha256=TwpbzEeZNd8Ju-EeoTsT5Ghd6opDJRT2YHuOnBkegDg,4479
25
25
  click_extended/core/other/__init__.py,sha256=ZYPlENo4widfcRWcg4yojmkNf_E89Y7U_8hRFCTOZoY,236
26
26
  click_extended/core/other/_click_command.py,sha256=NR7e-GyKiqyVJC8X5NjRXz5ehsYl9axVIxZCSejzUg4,1738
27
27
  click_extended/core/other/_click_group.py,sha256=BoEQoyx13n27Qy1-h_Dkaie68MlyPClIVB8cNtfPGdY,7714
@@ -52,7 +52,7 @@ click_extended/decorators/check/is_url.py,sha256=SLFO4v70CbuxOLr2zPMwH-CU8XqS1fa
52
52
  click_extended/decorators/check/is_uuid.py,sha256=QmCpQ6k7Z6zX0cICySqhKFr5wv0jkbGL7e1AA_jeFLw,844
53
53
  click_extended/decorators/check/length.py,sha256=guenyyVsoXHQcj0iZqqLcPxhujYTL6XKgBmgBmoG_Ls,1930
54
54
  click_extended/decorators/check/not_empty.py,sha256=TdznbvzhYJlWm2SoSxTTcpLT0SGLQMkXx8TTUhIqM5w,1125
55
- click_extended/decorators/check/regex.py,sha256=Vf6Tgx1gzmjKgWIT0nPtaFNv2taTdvVDXOWqmZg4Pm0,1066
55
+ click_extended/decorators/check/regex.py,sha256=J4lQ0_DllckXdJYhUBY65p8_HVl8SoKNJXn2Pc-revw,1945
56
56
  click_extended/decorators/check/requires.py,sha256=t_K4MIuli3oNkeHaNjIIEvwnwDop7bCrtKovL0HHz2c,5644
57
57
  click_extended/decorators/check/starts_with.py,sha256=0XDhJC9_2-BgDeb2ASnHWPhkXYFizHy47ns0M6dRjKg,2561
58
58
  click_extended/decorators/check/truthy.py,sha256=rfmQvHn-AN-y6knopta5PnYYvzgFVOkM1TqxDUI-nfw,748
@@ -143,9 +143,9 @@ click_extended/utils/naming.py,sha256=kNmzOqidgZZ1dE5aMYrxpWt4VwcLuEiFunpumpfHuZ
143
143
  click_extended/utils/process.py,sha256=sU3ZCMjBgjKcDnTRLKPdQ_TAjk0AT7Q8SatagD0JyHA,9729
144
144
  click_extended/utils/selection.py,sha256=_OQC88pGPUh29boxmS5ugXEi9jZGqAG180S27PeQaj0,9875
145
145
  click_extended/utils/time.py,sha256=H5m5caIEau_1GHkiYgKL_LcTtVdw2TkFVbkqJu7A9rQ,1067
146
- click_extended-1.0.5.dist-info/licenses/AUTHORS.md,sha256=NkShPinjqtnRDQVRyVnfJuOGM56sejauE3WRoYCcbtw,132
147
- click_extended-1.0.5.dist-info/licenses/LICENSE,sha256=gjO8hzM4mFSBXFikktaXVSgmXGcre91_GPJ-E_yP56E,1075
148
- click_extended-1.0.5.dist-info/METADATA,sha256=AMqloDv_MsOhytj3tOYCyFyd41WzbVcmZqZoFC5BjxU,10841
149
- click_extended-1.0.5.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
150
- click_extended-1.0.5.dist-info/top_level.txt,sha256=2G3bm6tCNv80okRm773jKTk-_z1ElY-seaozZrn_TxA,15
151
- click_extended-1.0.5.dist-info/RECORD,,
146
+ click_extended-1.0.7.dist-info/licenses/AUTHORS.md,sha256=NkShPinjqtnRDQVRyVnfJuOGM56sejauE3WRoYCcbtw,132
147
+ click_extended-1.0.7.dist-info/licenses/LICENSE,sha256=gjO8hzM4mFSBXFikktaXVSgmXGcre91_GPJ-E_yP56E,1075
148
+ click_extended-1.0.7.dist-info/METADATA,sha256=pVmPjkszY_IAx2DP-RM2i2IkhS28n_g6fkFU9itz8y4,10841
149
+ click_extended-1.0.7.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
150
+ click_extended-1.0.7.dist-info/top_level.txt,sha256=2G3bm6tCNv80okRm773jKTk-_z1ElY-seaozZrn_TxA,15
151
+ click_extended-1.0.7.dist-info/RECORD,,