Skip to content

Commit

Permalink
Fix transformers to allow hashing (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil authored Mar 5, 2024
1 parent 667ed62 commit 6ae4403
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lilya/_internal/_path_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
path_regex = re.compile(r"{([^:]+):([^}]+)}")


@dataclass
@dataclass(frozen=True, eq=True)
class Transformer(Generic[T]):
"""
Base for all path transformers
Expand All @@ -30,7 +30,7 @@ def normalise(self, value: T) -> str: # pragma: no cover
raise NotImplementedError() # pragma: no cover


@dataclass
@dataclass(frozen=True, eq=True)
class StringTransformer(Transformer[str]):
regex = "[^/]+"

Expand All @@ -44,7 +44,7 @@ def normalise(self, value: str) -> str:
return value


@dataclass
@dataclass(frozen=True, eq=True)
class PathTransformer(Transformer[str]):
regex = ".*"

Expand All @@ -55,7 +55,7 @@ def normalise(self, value: str) -> str:
return str(value)


@dataclass
@dataclass(frozen=True, eq=True)
class IntegerTransformer(Transformer[int]):
regex = "[0-9]+"

Expand All @@ -68,7 +68,7 @@ def normalise(self, value: int) -> str:
return str(value)


@dataclass
@dataclass(frozen=True, eq=True)
class FloatTransformer(Transformer[float]):
regex = r"[0-9]+(\.[0-9]+)?"

Expand All @@ -83,7 +83,7 @@ def normalise(self, value: float) -> str:
return ("%0.20f" % value).rstrip("0").rstrip(".")


@dataclass
@dataclass(frozen=True, eq=True)
class UUIDTransformer(Transformer[uuid.UUID]):
regex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"

Expand All @@ -94,7 +94,7 @@ def normalise(self, value: uuid.UUID) -> str:
return str(value)


@dataclass
@dataclass(frozen=True, eq=True)
class DatetimeTransformer(Transformer[datetime]):
regex = "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]+)?"

Expand Down

0 comments on commit 6ae4403

Please sign in to comment.