taipanstack 0.3.6__tar.gz → 0.3.7__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.
- {taipanstack-0.3.6 → taipanstack-0.3.7}/PKG-INFO +1 -1
- {taipanstack-0.3.6 → taipanstack-0.3.7}/pyproject.toml +1 -1
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/__init__.py +1 -1
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/decorators.py +6 -7
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/guards.py +18 -12
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/retry.py +43 -27
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/subprocess.py +3 -1
- {taipanstack-0.3.6 → taipanstack-0.3.7}/LICENSE +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/README.md +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/config/__init__.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/config/generators.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/config/models.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/config/version_config.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/core/__init__.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/core/compat.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/core/optimizations.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/core/result.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/__init__.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/jwt.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/password.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/sanitizers.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/types.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/validators.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/__init__.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/circuit_breaker.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/filesystem.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/logging.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/metrics.py +0 -0
- {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/rate_limit.py +0 -0
|
@@ -5,7 +5,7 @@ A modular, secure, and scalable Python stack for robust development.
|
|
|
5
5
|
Supports Python 3.11+ with version-aware optimizations for 3.13/3.14.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "0.3.
|
|
8
|
+
__version__ = "0.3.7"
|
|
9
9
|
|
|
10
10
|
from taipanstack.config.version_config import (
|
|
11
11
|
VersionRecommendations,
|
|
@@ -7,6 +7,7 @@ any Python framework (Flask, FastAPI, Django, etc.).
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
import functools
|
|
10
|
+
import inspect
|
|
10
11
|
import signal
|
|
11
12
|
import sys
|
|
12
13
|
import threading
|
|
@@ -83,12 +84,11 @@ def validate_inputs(
|
|
|
83
84
|
"""
|
|
84
85
|
|
|
85
86
|
def decorator(func: Callable[P, R]) -> Callable[P, R]:
|
|
87
|
+
sig = inspect.signature(func)
|
|
88
|
+
|
|
86
89
|
@functools.wraps(func)
|
|
87
90
|
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
88
|
-
#
|
|
89
|
-
import inspect
|
|
90
|
-
|
|
91
|
-
sig = inspect.signature(func)
|
|
91
|
+
# Bind and apply defaults on each call
|
|
92
92
|
bound = sig.bind(*args, **kwargs)
|
|
93
93
|
bound.apply_defaults()
|
|
94
94
|
|
|
@@ -353,11 +353,10 @@ def require_type(
|
|
|
353
353
|
"""
|
|
354
354
|
|
|
355
355
|
def decorator(func: Callable[P, R]) -> Callable[P, R]:
|
|
356
|
+
sig = inspect.signature(func)
|
|
357
|
+
|
|
356
358
|
@functools.wraps(func)
|
|
357
359
|
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
358
|
-
import inspect
|
|
359
|
-
|
|
360
|
-
sig = inspect.signature(func)
|
|
361
360
|
bound = sig.bind(*args, **kwargs)
|
|
362
361
|
bound.apply_defaults()
|
|
363
362
|
|
|
@@ -17,7 +17,8 @@ from urllib.parse import urlparse
|
|
|
17
17
|
from result import Err, Ok, Result
|
|
18
18
|
|
|
19
19
|
_TRAVERSAL_PATTERNS: frozenset[str] = frozenset(
|
|
20
|
-
|
|
20
|
+
p.lower()
|
|
21
|
+
for p in [
|
|
21
22
|
"..",
|
|
22
23
|
"~",
|
|
23
24
|
r"\.\.",
|
|
@@ -152,9 +153,10 @@ def guard_path_traversal(
|
|
|
152
153
|
|
|
153
154
|
# Check for explicit traversal patterns before resolution
|
|
154
155
|
path_str = str(path)
|
|
156
|
+
path_str_lower = path_str.lower()
|
|
155
157
|
|
|
156
158
|
for pattern in _TRAVERSAL_PATTERNS:
|
|
157
|
-
if pattern
|
|
159
|
+
if pattern in path_str_lower:
|
|
158
160
|
raise SecurityError(
|
|
159
161
|
f"Path traversal pattern detected: {pattern}",
|
|
160
162
|
guard_name="path_traversal",
|
|
@@ -163,7 +165,8 @@ def guard_path_traversal(
|
|
|
163
165
|
|
|
164
166
|
# Resolve the path
|
|
165
167
|
try:
|
|
166
|
-
|
|
168
|
+
full_path = path if path.is_absolute() else (base_dir / path)
|
|
169
|
+
resolved = full_path.resolve()
|
|
167
170
|
except (OSError, ValueError) as e:
|
|
168
171
|
raise SecurityError(
|
|
169
172
|
f"Invalid path: {e}",
|
|
@@ -181,15 +184,18 @@ def guard_path_traversal(
|
|
|
181
184
|
) from e
|
|
182
185
|
|
|
183
186
|
# Check for symlinks if not allowed
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
187
|
+
if not allow_symlinks:
|
|
188
|
+
current = full_path
|
|
189
|
+
# Only check components from the user-provided path, not the base_dir
|
|
190
|
+
while current not in (base_dir, current.parent):
|
|
191
|
+
# We don't check .exists() because it returns False for broken symlinks
|
|
192
|
+
if current.is_symlink():
|
|
193
|
+
raise SecurityError(
|
|
194
|
+
"Symlinks are not allowed",
|
|
195
|
+
guard_name="path_traversal",
|
|
196
|
+
value=str(current),
|
|
197
|
+
)
|
|
198
|
+
current = current.parent
|
|
193
199
|
|
|
194
200
|
return resolved
|
|
195
201
|
|
|
@@ -15,7 +15,7 @@ import time
|
|
|
15
15
|
from collections.abc import Callable
|
|
16
16
|
from dataclasses import dataclass
|
|
17
17
|
from types import TracebackType
|
|
18
|
-
from typing import Any, ParamSpec, TypeVar, cast
|
|
18
|
+
from typing import Any, NoReturn, ParamSpec, TypeVar, cast
|
|
19
19
|
|
|
20
20
|
P = ParamSpec("P")
|
|
21
21
|
R = TypeVar("R")
|
|
@@ -176,6 +176,38 @@ def _log_all_failed(
|
|
|
176
176
|
)
|
|
177
177
|
|
|
178
178
|
|
|
179
|
+
def _raise_retry_error(
|
|
180
|
+
func_name: str,
|
|
181
|
+
max_attempts: int,
|
|
182
|
+
reraise: bool,
|
|
183
|
+
last_exception: Exception | None,
|
|
184
|
+
) -> NoReturn:
|
|
185
|
+
"""Raise a RetryError after all attempts fail.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
func_name: Name of the retried function.
|
|
189
|
+
max_attempts: Number of attempts made.
|
|
190
|
+
reraise: Whether to reraise the original exception.
|
|
191
|
+
last_exception: The last exception that was raised.
|
|
192
|
+
|
|
193
|
+
Raises:
|
|
194
|
+
RetryError: The wrapped or unwrapped exception.
|
|
195
|
+
|
|
196
|
+
"""
|
|
197
|
+
if reraise and last_exception is not None:
|
|
198
|
+
raise RetryError(
|
|
199
|
+
f"All {max_attempts} attempts failed for {func_name}",
|
|
200
|
+
attempts=max_attempts,
|
|
201
|
+
last_exception=last_exception,
|
|
202
|
+
) from last_exception
|
|
203
|
+
|
|
204
|
+
raise RetryError(
|
|
205
|
+
f"All {max_attempts} attempts failed for {func_name}",
|
|
206
|
+
attempts=max_attempts,
|
|
207
|
+
last_exception=last_exception,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
|
|
179
211
|
def retry(
|
|
180
212
|
*,
|
|
181
213
|
max_attempts: int = 3,
|
|
@@ -261,19 +293,11 @@ def retry(
|
|
|
261
293
|
)
|
|
262
294
|
await asyncio.sleep(delay)
|
|
263
295
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
last_exception=last_exception,
|
|
270
|
-
) from last_exception
|
|
271
|
-
|
|
272
|
-
# Should never reach here if reraise=True
|
|
273
|
-
raise RetryError(
|
|
274
|
-
f"All {max_attempts} attempts failed for {func.__name__}",
|
|
275
|
-
attempts=max_attempts,
|
|
276
|
-
last_exception=last_exception,
|
|
296
|
+
_raise_retry_error(
|
|
297
|
+
func.__name__,
|
|
298
|
+
max_attempts,
|
|
299
|
+
reraise,
|
|
300
|
+
last_exception,
|
|
277
301
|
)
|
|
278
302
|
|
|
279
303
|
return cast(F, async_wrapper)
|
|
@@ -307,19 +331,11 @@ def retry(
|
|
|
307
331
|
)
|
|
308
332
|
time.sleep(delay)
|
|
309
333
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
last_exception=last_exception,
|
|
316
|
-
) from last_exception
|
|
317
|
-
|
|
318
|
-
# Should never reach here if reraise=True
|
|
319
|
-
raise RetryError(
|
|
320
|
-
f"All {max_attempts} attempts failed for {func.__name__}",
|
|
321
|
-
attempts=max_attempts,
|
|
322
|
-
last_exception=last_exception,
|
|
334
|
+
_raise_retry_error(
|
|
335
|
+
func.__name__,
|
|
336
|
+
max_attempts,
|
|
337
|
+
reraise,
|
|
338
|
+
last_exception,
|
|
323
339
|
)
|
|
324
340
|
|
|
325
341
|
return cast(F, wrapper)
|
|
@@ -295,7 +295,7 @@ def run_git_command(
|
|
|
295
295
|
)
|
|
296
296
|
|
|
297
297
|
|
|
298
|
-
def check_command_exists(command: str) -> bool:
|
|
298
|
+
def check_command_exists(command: str | None) -> bool:
|
|
299
299
|
"""Check if a command exists in PATH.
|
|
300
300
|
|
|
301
301
|
Args:
|
|
@@ -305,6 +305,8 @@ def check_command_exists(command: str) -> bool:
|
|
|
305
305
|
True if command exists, False otherwise.
|
|
306
306
|
|
|
307
307
|
"""
|
|
308
|
+
if not command:
|
|
309
|
+
return False
|
|
308
310
|
return shutil.which(command) is not None
|
|
309
311
|
|
|
310
312
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|