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.
Files changed (29) hide show
  1. {taipanstack-0.3.6 → taipanstack-0.3.7}/PKG-INFO +1 -1
  2. {taipanstack-0.3.6 → taipanstack-0.3.7}/pyproject.toml +1 -1
  3. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/__init__.py +1 -1
  4. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/decorators.py +6 -7
  5. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/guards.py +18 -12
  6. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/retry.py +43 -27
  7. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/subprocess.py +3 -1
  8. {taipanstack-0.3.6 → taipanstack-0.3.7}/LICENSE +0 -0
  9. {taipanstack-0.3.6 → taipanstack-0.3.7}/README.md +0 -0
  10. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/config/__init__.py +0 -0
  11. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/config/generators.py +0 -0
  12. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/config/models.py +0 -0
  13. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/config/version_config.py +0 -0
  14. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/core/__init__.py +0 -0
  15. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/core/compat.py +0 -0
  16. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/core/optimizations.py +0 -0
  17. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/core/result.py +0 -0
  18. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/__init__.py +0 -0
  19. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/jwt.py +0 -0
  20. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/password.py +0 -0
  21. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/sanitizers.py +0 -0
  22. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/types.py +0 -0
  23. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/security/validators.py +0 -0
  24. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/__init__.py +0 -0
  25. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/circuit_breaker.py +0 -0
  26. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/filesystem.py +0 -0
  27. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/logging.py +0 -0
  28. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/metrics.py +0 -0
  29. {taipanstack-0.3.6 → taipanstack-0.3.7}/src/taipanstack/utils/rate_limit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taipanstack
3
- Version: 0.3.6
3
+ Version: 0.3.7
4
4
  Summary: TaipanStack - Modular, secure, and scalable Python stack for robust development
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "taipanstack"
3
- version = "0.3.6"
3
+ version = "0.3.7"
4
4
  description = "TaipanStack - Modular, secure, and scalable Python stack for robust development"
5
5
  authors = [
6
6
  {name = "gabrielima7", email = "gabrielima.alu.lmb@gmail.com"}
@@ -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.6"
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
- # Get function's parameter names
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.lower() in path_str.lower():
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
- resolved = path.resolve() if path.is_absolute() else (base_dir / path).resolve()
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
- is_existing_symlink = (
185
- not allow_symlinks and resolved.exists() and resolved.is_symlink()
186
- )
187
- if is_existing_symlink:
188
- raise SecurityError(
189
- "Symlinks are not allowed",
190
- guard_name="path_traversal",
191
- value=str(resolved),
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
- # All attempts failed
265
- if reraise and last_exception is not None:
266
- raise RetryError(
267
- f"All {max_attempts} attempts failed for {func.__name__}",
268
- attempts=max_attempts,
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
- # All attempts failed
311
- if reraise and last_exception is not None:
312
- raise RetryError(
313
- f"All {max_attempts} attempts failed for {func.__name__}",
314
- attempts=max_attempts,
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