Skip to content

Commit

Permalink
Refactored remote/client_config.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepsuryaprasad committed Dec 14, 2024
1 parent 89b84ae commit 3da1654
Showing 1 changed file with 38 additions and 168 deletions.
206 changes: 38 additions & 168 deletions py/selenium/webdriver/remote/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,45 @@ 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,179 +117,11 @@ 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."""
Expand Down

0 comments on commit 3da1654

Please sign in to comment.