Compare commits

...

1 Commits

3 changed files with 11 additions and 14 deletions

View File

@ -149,13 +149,11 @@ class CookieRequestParameters(RequestParameters):
except KeyError: except KeyError:
return super().get(name, default) return super().get(name, default)
def getlist( def getlist(self, name: str) -> list[Any]:
self, name: str, default: Optional[Any] = None
) -> Optional[Any]:
try: try:
return self._get_prefixed_cookie(name) return self._get_prefixed_cookie(name)
except KeyError: except KeyError:
return super().getlist(name, default) return super().getlist(name)
def _get_prefixed_cookie(self, name: str) -> Any: def _get_prefixed_cookie(self, name: str) -> Any:
getitem = super().__getitem__ getitem = super().__getitem__

View File

@ -19,15 +19,14 @@ class RequestParameters(dict):
return super().get(name, [default])[0] return super().get(name, [default])[0]
def getlist( def getlist(
self, name: str, default: Optional[Any] = None self, name: str
) -> Optional[Any]: ) -> list[Any]:
"""Return the entire list """Return the entire list
Args: Args:
name (str): The name of the parameter name (str): The name of the parameter
default (Optional[Any], optional): The default value. Defaults to None.
Returns: Returns:
Optional[Any]: The entire list list[Any]: The entire list of values or [] if not found
""" # noqa: E501 """ # noqa: E501
return super().get(name, default) return super().get(name) or []

View File

@ -445,10 +445,10 @@ def test_cookie_accessors(app: Sanic):
"four": request.cookies.get("four", "fallback"), "four": request.cookies.get("four", "fallback"),
}, },
"getlist": { "getlist": {
"one": request.cookies.getlist("one", ["fallback"]), "one": request.cookies.getlist("one"),
"two": request.cookies.getlist("two", ["fallback"]), "two": request.cookies.getlist("two"),
"three": request.cookies.getlist("three", ["fallback"]), "three": request.cookies.getlist("three"),
"four": request.cookies.getlist("four", ["fallback"]), "four": request.cookies.getlist("four"),
}, },
"getattr": { "getattr": {
"one": request.cookies.one, "one": request.cookies.one,
@ -484,7 +484,7 @@ def test_cookie_accessors(app: Sanic):
"one": ["1"], "one": ["1"],
"two": ["2"], "two": ["2"],
"three": ["3"], "three": ["3"],
"four": ["fallback"], "four": [],
}, },
"getattr": { "getattr": {
"one": "1", "one": "1",