diff --git a/scrapling/engines/_browsers/_validators.py b/scrapling/engines/_browsers/_validators.py index b148fe6..b5740b4 100644 --- a/scrapling/engines/_browsers/_validators.py +++ b/scrapling/engines/_browsers/_validators.py @@ -96,7 +96,7 @@ class PlaywrightConfig(Struct, kw_only=True, frozen=False, weakref=True): if self.page_action and not callable(self.page_action): raise TypeError(f"page_action must be callable, got {type(self.page_action).__name__}") if self.proxy: - self.proxy = construct_proxy_dict(self.proxy, as_tuple=True) + self.proxy = construct_proxy_dict(self.proxy) if self.cdp_url: cdp_msg = _is_invalid_cdp_url(self.cdp_url) if cdp_msg: diff --git a/scrapling/engines/toolbelt/navigation.py b/scrapling/engines/toolbelt/navigation.py index 959aa5f..9aa91dd 100644 --- a/scrapling/engines/toolbelt/navigation.py +++ b/scrapling/engines/toolbelt/navigation.py @@ -49,20 +49,11 @@ async def async_intercept_route(route: async_Route): await route.continue_() -@overload -def construct_proxy_dict(proxy_string: str | Dict[str, str] | Tuple, as_tuple: Literal[True]) -> Tuple: ... - - -@overload -def construct_proxy_dict(proxy_string: str | Dict[str, str] | Tuple, as_tuple: Literal[False] = False) -> Dict: ... - - -def construct_proxy_dict(proxy_string: str | Dict[str, str] | Tuple, as_tuple: bool = False) -> Dict | Tuple: +def construct_proxy_dict(proxy_string: str | Dict[str, str] | Tuple) -> Dict: """Validate a proxy and return it in the acceptable format for Playwright Reference: https://playwright.dev/python/docs/network#http-proxy :param proxy_string: A string or a dictionary representation of the proxy. - :param as_tuple: Return the proxy dictionary as a tuple to be cachable :return: """ if isinstance(proxy_string, str): @@ -78,7 +69,7 @@ def construct_proxy_dict(proxy_string: str | Dict[str, str] | Tuple, as_tuple: b } if proxy.port: result["server"] += f":{proxy.port}" - return tuple(result.items()) if as_tuple else result + return result except ValueError: # Urllib will say that one of the parameters above can't be casted to the correct type like `int` for port etc... raise ValueError("The proxy argument's string is in invalid format!") @@ -87,7 +78,7 @@ def construct_proxy_dict(proxy_string: str | Dict[str, str] | Tuple, as_tuple: b try: validated = convert(proxy_string, ProxyDict) result_dict = structs.asdict(validated) - return tuple(result_dict.items()) if as_tuple else result_dict + return result_dict except ValidationError as e: raise TypeError(f"Invalid proxy dictionary: {e}")