Compare commits
	
		
			1 Commits
		
	
	
		
			remove-get
			...
			tlspath
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 340fea7da5 | 
| @@ -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__ | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ from __future__ import annotations | |||||||
| import os | import os | ||||||
| import ssl | import ssl | ||||||
|  |  | ||||||
|  | from pathlib import Path, PurePath | ||||||
| from typing import Any, Dict, Iterable, Optional, Union | from typing import Any, Dict, Iterable, Optional, Union | ||||||
|  |  | ||||||
| from sanic.log import logger | from sanic.log import logger | ||||||
| @@ -39,23 +40,23 @@ def create_context( | |||||||
|  |  | ||||||
|  |  | ||||||
| def shorthand_to_ctx( | def shorthand_to_ctx( | ||||||
|     ctxdef: Union[None, ssl.SSLContext, dict, str] |     ctxdef: Union[None, ssl.SSLContext, dict, PurePath, str] | ||||||
| ) -> Optional[ssl.SSLContext]: | ) -> Optional[ssl.SSLContext]: | ||||||
|     """Convert an ssl argument shorthand to an SSLContext object.""" |     """Convert an ssl argument shorthand to an SSLContext object.""" | ||||||
|     if ctxdef is None or isinstance(ctxdef, ssl.SSLContext): |     if ctxdef is None or isinstance(ctxdef, ssl.SSLContext): | ||||||
|         return ctxdef |         return ctxdef | ||||||
|     if isinstance(ctxdef, str): |     if isinstance(ctxdef, (PurePath, str)): | ||||||
|         return load_cert_dir(ctxdef) |         return load_cert_dir(Path(ctxdef)) | ||||||
|     if isinstance(ctxdef, dict): |     if isinstance(ctxdef, dict): | ||||||
|         return CertSimple(**ctxdef) |         return CertSimple(**ctxdef) | ||||||
|     raise ValueError( |     raise ValueError( | ||||||
|         f"Invalid ssl argument {type(ctxdef)}." |         f"Invalid ssl argument {type(ctxdef)}." | ||||||
|         " Expecting a list of certdirs, a dict or an SSLContext." |         " Expecting one/list of: certdir | dict | SSLContext" | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |  | ||||||
| def process_to_context( | def process_to_context( | ||||||
|     ssldef: Union[None, ssl.SSLContext, dict, str, list, tuple] |     ssldef: Union[None, ssl.SSLContext, dict, PurePath, str, list, tuple] | ||||||
| ) -> Optional[ssl.SSLContext]: | ) -> Optional[ssl.SSLContext]: | ||||||
|     """Process app.run ssl argument from easy formats to full SSLContext.""" |     """Process app.run ssl argument from easy formats to full SSLContext.""" | ||||||
|     return ( |     return ( | ||||||
| @@ -65,11 +66,11 @@ def process_to_context( | |||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |  | ||||||
| def load_cert_dir(p: str) -> ssl.SSLContext: | def load_cert_dir(p: Path) -> ssl.SSLContext: | ||||||
|     if os.path.isfile(p): |     if p.is_file(): | ||||||
|         raise ValueError(f"Certificate folder expected but {p} is a file.") |         raise ValueError(f"Certificate folder expected but {p} is a file.") | ||||||
|     keyfile = os.path.join(p, "privkey.pem") |     keyfile = p / "privkey.pem" | ||||||
|     certfile = os.path.join(p, "fullchain.pem") |     certfile = p / "fullchain.pem" | ||||||
|     if not os.access(keyfile, os.R_OK): |     if not os.access(keyfile, os.R_OK): | ||||||
|         raise ValueError( |         raise ValueError( | ||||||
|             f"Certificate not found or permission denied {keyfile}" |             f"Certificate not found or permission denied {keyfile}" | ||||||
|   | |||||||
| @@ -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", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user