Path: blob/trunk/py/selenium/webdriver/webkitgtk/service.py
1864 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 shutil18import warnings19from collections.abc import Mapping, Sequence20from typing import Optional2122from selenium.webdriver.common import service2324DEFAULT_EXECUTABLE_PATH: str = shutil.which("WebKitWebDriver")252627class Service(service.Service):28"""A Service class that is responsible for the starting and stopping of29`WebKitWebDriver`.3031:param executable_path: install path of the WebKitWebDriver executable, defaults to the first32`WebKitWebDriver` in `$PATH`.33:param port: Port for the service to run on, defaults to 0 where the operating system will decide.34:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.35:param log_output: (Optional) File path for the file to be opened and passed as the subprocess36stdout/stderr handler.37:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.38"""3940def __init__(41self,42executable_path: str = DEFAULT_EXECUTABLE_PATH,43port: int = 0,44log_path: Optional[str] = None,45log_output: Optional[str] = None,46service_args: Optional[Sequence[str]] = None,47env: Optional[Mapping[str, str]] = None,48**kwargs,49) -> None:50self._service_args = list(service_args or [])51if log_path is not None:52warnings.warn("log_path is deprecated, use log_output instead", DeprecationWarning, stacklevel=2)53log_path = open(log_path, "wb")54log_output = open(log_output, "wb") if log_output else None5556super().__init__(57executable_path=executable_path,58port=port,59log_output=log_path or log_output,60env=env,61**kwargs,62)6364def command_line_args(self) -> list[str]:65return ["-p", f"{self.port}"] + self._service_args6667@property68def service_args(self) -> Sequence[str]:69return self._service_args7071@service_args.setter72def service_args(self, value: Sequence[str]):73if isinstance(value, str) or not isinstance(value, Sequence):74raise TypeError("service_args must be a sequence")75self._service_args = list(value)767778