Path: blob/trunk/py/selenium/webdriver/ie/service.py
4057 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import logging18import os19import sys20from collections.abc import Sequence21from typing import IO, Any2223from selenium.webdriver.common import service242526class Service(service.Service):27"""Service class responsible for starting and stopping of `IEDriver`.2829Args:30executable_path: (Optional) Install path of the executable.31port: (Optional) Port for the service to run on, defaults to 0 where the operating system will decide.32host: (Optional) IP address the service port is bound33service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.34log_level: (Optional) Level of logging of service, may be "FATAL", "ERROR", "WARN", "INFO", "DEBUG",35"TRACE". Default is "FATAL".36log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file.37driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable.38**kwargs: Additional keyword arguments to pass to the parent Service class.39"""4041def __init__(42self,43executable_path: str | None = None,44port: int = 0,45host: str | None = None,46service_args: Sequence[str] | None = None,47log_level: str | None = None,48log_output: int | str | IO[Any] | None = None,49driver_path_env_key: str | None = None,50**kwargs,51) -> None:52self._service_args = list(service_args or [])53driver_path_env_key = driver_path_env_key or "SE_IEDRIVER"5455if host:56self._service_args.append(f"--host={host}")57if log_level:58self._service_args.append(f"--log-level={log_level}")5960if os.environ.get("SE_DEBUG"):61has_arg_conflicts = any(x in arg for arg in self._service_args for x in ("log-level", "log-file"))62has_output_conflict = log_output is not None63if has_arg_conflicts or has_output_conflict:64logging.getLogger(__name__).warning(65"Environment Variable `SE_DEBUG` is set; "66"forcing IEDriver log level to DEBUG and overriding configured log level/output."67)68if has_arg_conflicts:69self._service_args = [70arg for arg in self._service_args if not any(x in arg for x in ("log-level", "log-file"))71]72self._service_args.append("--log-level=DEBUG")73log_output = sys.stderr7475super().__init__(76executable_path=executable_path,77port=port,78log_output=log_output,79driver_path_env_key=driver_path_env_key,80**kwargs,81)8283def command_line_args(self) -> list[str]:84return [f"--port={self.port}"] + self._service_args8586@property87def service_args(self) -> Sequence[str]:88"""Returns the sequence of service arguments."""89return self._service_args9091@service_args.setter92def service_args(self, value: Sequence[str]):93if isinstance(value, str) or not isinstance(value, Sequence):94raise TypeError("service_args must be a sequence")95self._service_args = list(value)969798