Skip to content

[py] Refactored remote/client_config.py by moving properties into descriptor object #14899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 41 additions & 170 deletions py/selenium/webdriver/remote/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,48 @@ class AuthType(Enum):
X_API_KEY = "X-API-Key"


class _ClientConfigDescriptor:
def __init__(self, name):
self.name = name

def __get__(self, obj, cls):
return obj.__dict__[self.name]

def __set__(self, obj, value) -> None:
obj.__dict__[self.name] = value


class ClientConfig:
remote_server_addr = _ClientConfigDescriptor("_remote_server_addr")
"""Gets and Sets Remote Server."""
keep_alive = _ClientConfigDescriptor("_keep_alive")
"""Gets and Sets Keep Alive value."""
proxy = _ClientConfigDescriptor("_proxy")
"""Gets and Sets the proxy used for communicating to the driver/server."""
ignore_certificates = _ClientConfigDescriptor("_ignore_certificates")
"""Gets and Sets the ignore certificate check value."""
init_args_for_pool_manager = _ClientConfigDescriptor("_init_args_for_pool_manager")
"""Gets and Sets the ignore certificate check."""
timeout = _ClientConfigDescriptor("_timeout")
"""Gets and Sets the timeout (in seconds) used for communicating to the
driver/server."""
ca_certs = _ClientConfigDescriptor("_ca_certs")
"""Gets and Sets the path to bundle of CA certificates."""
username = _ClientConfigDescriptor("_username")
"""Gets and Sets the username used for basic authentication to the
remote."""
password = _ClientConfigDescriptor("_password")
"""Gets and Sets the password used for basic authentication to the
remote."""
auth_type = _ClientConfigDescriptor("_auth_type")
"""Gets and Sets the type of authentication to the remote server."""
token = _ClientConfigDescriptor("_token")
"""Gets and Sets the token used for authentication to the remote server."""
user_agent = _ClientConfigDescriptor("_user_agent")
"""Gets and Sets user agent to be added to the request headers."""
extra_headers = _ClientConfigDescriptor("_extra_headers")
"""Gets and Sets extra headers to be added to the request."""

def __init__(
self,
remote_server_addr: str,
Expand Down Expand Up @@ -79,180 +120,10 @@ def __init__(
else ca_certs
)

@property
def remote_server_addr(self) -> str:
""":Returns: The address of the remote server."""
return self._remote_server_addr

@remote_server_addr.setter
def remote_server_addr(self, value: str) -> None:
"""Provides the address of the remote server."""
self._remote_server_addr = value

@property
def keep_alive(self) -> bool:
""":Returns: The keep alive value."""
return self._keep_alive

@keep_alive.setter
def keep_alive(self, value: bool) -> None:
"""Toggles the keep alive value.

:Args:
- value: whether to keep the http connection alive
"""
self._keep_alive = value

@property
def proxy(self) -> Proxy:
""":Returns: The proxy used for communicating to the driver/server."""
return self._proxy

@proxy.setter
def proxy(self, proxy: Proxy) -> None:
"""Provides the information for communicating with the driver or
server.
For example: Proxy(raw={"proxyType": ProxyType.SYSTEM})

:Args:
- value: the proxy information to use to communicate with the driver or server
"""
self._proxy = proxy

@property
def ignore_certificates(self) -> bool:
""":Returns: The ignore certificate check value."""
return self._ignore_certificates

@ignore_certificates.setter
def ignore_certificates(self, ignore_certificates: bool) -> None:
"""Toggles the ignore certificate check.

:Args:
- value: value of ignore certificate check
"""
self._ignore_certificates = ignore_certificates

@property
def init_args_for_pool_manager(self) -> dict:
""":Returns: The dictionary of arguments will be appended while
initializing the pool manager."""
return self._init_args_for_pool_manager

@init_args_for_pool_manager.setter
def init_args_for_pool_manager(self, init_args_for_pool_manager: dict) -> None:
"""Provides dictionary of arguments will be appended while initializing the pool manager.
For example: {"init_args_for_pool_manager": {"retries": 3, "block": True}}

:Args:
- value: the dictionary of arguments will be appended while initializing the pool manager
"""
self._init_args_for_pool_manager = init_args_for_pool_manager

@property
def timeout(self) -> int:
""":Returns: The timeout (in seconds) used for communicating to the
driver/server."""
return self._timeout

@timeout.setter
def timeout(self, timeout: int) -> None:
"""Provides the timeout (in seconds) for communicating with the driver
or server.

:Args:
- value: the timeout (in seconds) to use to communicate with the driver or server
"""
self._timeout = timeout

def reset_timeout(self) -> None:
"""Resets the timeout to the default value of socket."""
self._timeout = socket.getdefaulttimeout()

@property
def ca_certs(self) -> str:
""":Returns: The path to bundle of CA certificates."""
return self._ca_certs

@ca_certs.setter
def ca_certs(self, ca_certs: str) -> None:
"""Provides the path to bundle of CA certificates for establishing
secure connections.

:Args:
- value: the path to bundle of CA certificates for establishing secure connections
"""
self._ca_certs = ca_certs

@property
def username(self) -> str:
"""Returns the username used for basic authentication to the remote
server."""
return self._username

@username.setter
def username(self, value: str) -> None:
"""Sets the username used for basic authentication to the remote
server."""
self._username = value

@property
def password(self) -> str:
"""Returns the password used for basic authentication to the remote
server."""
return self._password

@password.setter
def password(self, value: str) -> None:
"""Sets the password used for basic authentication to the remote
server."""
self._password = value

@property
def auth_type(self) -> AuthType:
"""Returns the type of authentication to the remote server."""
return self._auth_type

@auth_type.setter
def auth_type(self, value: AuthType) -> None:
"""Sets the type of authentication to the remote server if it is not
using basic with username and password.

:Args: value - AuthType enum value. For others, please use `extra_headers` instead
"""
self._auth_type = value

@property
def token(self) -> str:
"""Returns the token used for authentication to the remote server."""
return self._token

@token.setter
def token(self, value: str) -> None:
"""Sets the token used for authentication to the remote server if
auth_type is not basic."""
self._token = value

@property
def user_agent(self) -> str:
"""Returns user agent to be added to the request headers."""
return self._user_agent

@user_agent.setter
def user_agent(self, value: str) -> None:
"""Sets user agent to be added to the request headers."""
self._user_agent = value

@property
def extra_headers(self) -> dict:
"""Returns extra headers to be added to the request."""
return self._extra_headers

@extra_headers.setter
def extra_headers(self, value: dict) -> None:
"""Sets extra headers to be added to the request."""
self._extra_headers = value

def get_proxy_url(self) -> Optional[str]:
"""Returns the proxy URL to use for the connection."""
proxy_type = self.proxy.proxy_type
Expand Down
Loading