🎨 Add URLTypes

This commit is contained in:
洛水居室 2023-06-12 10:59:36 +08:00
parent 27325f2791
commit 15c7228e2c
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
2 changed files with 8 additions and 6 deletions

View File

@ -18,6 +18,7 @@ from simnet.utils.types import (
RequestData,
QueryParamTypes,
TimeoutTypes,
URLTypes,
)
_LOGGER = logging.getLogger("SIMNet.BaseClient")
@ -223,7 +224,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
async def request(
self,
method: str,
url: str,
url: URLTypes,
data: Optional[RequestData] = None,
json: Optional[Any] = None,
params: Optional[QueryParamTypes] = None,
@ -237,7 +238,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
Args:
method (str): The HTTP method to use for the request (e.g., "GET", "POST").
url (str): The URL to send the request to.
url (URLTypes): The URL to send the request to.
data (Optional[RequestData]): The request data to include in the body of the request.
json (Optional[Any]): The JSON payload to include in the body of the request.
params (Optional[QueryParamTypes]): The query parameters to include in the request.
@ -268,7 +269,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
async def request_api(
self,
method: str,
url: str,
url: URLTypes,
json: Optional[Any] = None,
params: Optional[QueryParamTypes] = None,
headers: Optional[HeaderTypes] = None,
@ -281,7 +282,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
Args:
method (str): The HTTP method to use for the request (e.g., "GET", "POST").
url (str): The URL to send the request to.
url (URLTypes): The URL to send the request to.
json (Optional[Any]): The JSON payload to include in the body of the request.
params (Optional[QueryParamTypes]): The query parameters to include in the request.
headers (Optional[HeaderTypes]): The headers to include in the request.
@ -314,7 +315,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
async def request_lab(
self,
url: str,
url: URLTypes,
method: Optional[str] = None,
data: Optional[Any] = None,
params: Optional[QueryParamTypes] = None,
@ -330,7 +331,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
It also adds headers for the lab API and handles the case where the method is not specified.
Args:
url (str): The URL to send the request to.
url (URLTypes): The URL to send the request to.
method (Optional[str]): The HTTP method to use for the request (e.g., "GET", "POST").
data (Optional[Any]): The JSON payload to include in the body of the request.
params (Optional[QueryParamTypes]): The query parameters to include in the request.

View File

@ -2,6 +2,7 @@ from typing import TypeVar, Union, Mapping, Optional, Sequence, Dict, List, Tupl
RT = TypeVar("RT", bound="BaseClient")
URLTypes = Union["URL", str]
CookieTypes = Union["Cookie", Dict[str, str], List[Tuple[str, str]]]
RequestData = Mapping[str, Any]