Compare commits
No commits in common. "remove-getlist-fallback" and "main" have entirely different histories.
remove-get
...
main
|
@ -149,11 +149,13 @@ class CookieRequestParameters(RequestParameters):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return super().get(name, default)
|
return super().get(name, default)
|
||||||
|
|
||||||
def getlist(self, name: str) -> list[Any]:
|
def getlist(
|
||||||
|
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)
|
return super().getlist(name, default)
|
||||||
|
|
||||||
def _get_prefixed_cookie(self, name: str) -> Any:
|
def _get_prefixed_cookie(self, name: str) -> Any:
|
||||||
getitem = super().__getitem__
|
getitem = super().__getitem__
|
||||||
|
|
|
@ -19,14 +19,15 @@ class RequestParameters(dict):
|
||||||
return super().get(name, [default])[0]
|
return super().get(name, [default])[0]
|
||||||
|
|
||||||
def getlist(
|
def getlist(
|
||||||
self, name: str
|
self, name: str, default: Optional[Any] = None
|
||||||
) -> list[Any]:
|
) -> Optional[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:
|
||||||
list[Any]: The entire list of values or [] if not found
|
Optional[Any]: The entire list
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
return super().get(name) or []
|
return super().get(name, default)
|
||||||
|
|
|
@ -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"),
|
"one": request.cookies.getlist("one", ["fallback"]),
|
||||||
"two": request.cookies.getlist("two"),
|
"two": request.cookies.getlist("two", ["fallback"]),
|
||||||
"three": request.cookies.getlist("three"),
|
"three": request.cookies.getlist("three", ["fallback"]),
|
||||||
"four": request.cookies.getlist("four"),
|
"four": request.cookies.getlist("four", ["fallback"]),
|
||||||
},
|
},
|
||||||
"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": [],
|
"four": ["fallback"],
|
||||||
},
|
},
|
||||||
"getattr": {
|
"getattr": {
|
||||||
"one": "1",
|
"one": "1",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user