generated from coulomb/repo-seed
Add hub-core package, docs, and State Hub integration scaffold
Extract the first reusable slice (models, schemas, routers, MCP, migrations) from state-hub with INTENT/SCOPE, agent instructions, workplan, and aligned inter_hub capability registry index.
This commit is contained in:
27
hub_core/utils/routing.py
Normal file
27
hub_core/utils/routing.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from urllib.parse import SplitResult, urlsplit, urlunsplit
|
||||
|
||||
|
||||
def normalize_trailing_slash(path_or_url: str, *, trailing: bool = True) -> str:
|
||||
"""Normalize the path component while preserving query and fragment."""
|
||||
if not path_or_url:
|
||||
return "/" if trailing else ""
|
||||
|
||||
parts = urlsplit(path_or_url)
|
||||
path = parts.path or "/"
|
||||
if trailing:
|
||||
normalized_path = path if path.endswith("/") else f"{path}/"
|
||||
elif path == "/":
|
||||
normalized_path = "/"
|
||||
else:
|
||||
normalized_path = path.rstrip("/")
|
||||
|
||||
if parts.scheme or parts.netloc:
|
||||
return urlunsplit(
|
||||
SplitResult(parts.scheme, parts.netloc, normalized_path, parts.query, parts.fragment)
|
||||
)
|
||||
suffix = ""
|
||||
if parts.query:
|
||||
suffix += f"?{parts.query}"
|
||||
if parts.fragment:
|
||||
suffix += f"#{parts.fragment}"
|
||||
return f"{normalized_path}{suffix}"
|
||||
Reference in New Issue
Block a user