Skip to content

Commit

Permalink
[Update] model: param support
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien committed Sep 26, 2024
1 parent 1f9624a commit 2953a0a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/py/extra/http/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Union,
Callable,
AsyncGenerator,
TypeVar,
)
from abc import ABC, abstractmethod
from functools import cached_property
Expand All @@ -23,6 +24,7 @@
# NOTE: MyPyC doesn't support async generators. We're trying without.

TControl = bool | None
T = TypeVar("T")


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -243,8 +245,14 @@ def getHeader(self, name: str) -> str | None:
def header(self, name: str) -> str | None:
return self._headers.headers.get(headername(name))

def param(self, name: str) -> str | None:
return self.query.get(name) if self.query else None
def param(
self,
name: str,
default: T | None = None,
processor: Callable[[str | T | None], str | T | None] | None = None,
) -> str | T | None:
v = self.query.get(name, default) if self.query else default
return processor(v) if processor else v

@property
def contentType(self) -> str | None:
Expand Down

0 comments on commit 2953a0a

Please sign in to comment.