mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-10-26 17:41:58 -06:00
27 lines
743 B
Python
27 lines
743 B
Python
from __future__ import annotations
|
|
|
|
import string
|
|
import uuid
|
|
from typing import Optional
|
|
|
|
|
|
def normalize_guid(value: Optional[str]) -> str:
|
|
"""
|
|
Canonicalize GUID strings so the server treats different casings/formats uniformly.
|
|
"""
|
|
candidate = (value or "").strip()
|
|
if not candidate:
|
|
return ""
|
|
candidate = candidate.strip("{}")
|
|
try:
|
|
return str(uuid.UUID(candidate)).upper()
|
|
except Exception:
|
|
cleaned = "".join(ch for ch in candidate if ch in string.hexdigits or ch == "-")
|
|
cleaned = cleaned.strip("-")
|
|
if cleaned:
|
|
try:
|
|
return str(uuid.UUID(cleaned)).upper()
|
|
except Exception:
|
|
pass
|
|
return candidate.upper()
|