Path: blob/trunk/py/selenium/webdriver/wpewebkit/service.py
3989 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 shutil18from collections.abc import Mapping, Sequence19from typing import IO, Any2021from selenium.webdriver.common import service2223DEFAULT_EXECUTABLE_PATH: str | None = shutil.which("WPEWebDriver")242526class Service(service.Service):27"""Service class that is responsible for the starting and stopping of `WPEWebDriver`.2829Args:30executable_path: (Optional) Install path of the WPEWebDriver executable, defaults to the first `WPEWebDriver`31in `$PATH`.32port: (Optional) Port for the service to run on, defaults to 0 where the operating system will decide.33service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.34log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file.35env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.36"""3738def __init__(39self,40executable_path: str | None = DEFAULT_EXECUTABLE_PATH,41port: int = 0,42log_output: int | str | IO[Any] | None = None,43service_args: Sequence[str] | None = None,44env: Mapping[str, str] | None = None,45**kwargs,46):47self._service_args = list(service_args or [])4849super().__init__(50executable_path=executable_path,51port=port,52log_output=log_output,53env=env,54**kwargs,55)5657def command_line_args(self) -> list[str]:58return ["-p", f"{self.port}"] + self._service_args5960@property61def service_args(self) -> Sequence[str]:62"""Returns the sequence of service arguments."""63return self._service_args6465@service_args.setter66def service_args(self, value: Sequence[str]):67if isinstance(value, str) or not isinstance(value, Sequence):68raise TypeError("service_args must be a sequence")69self._service_args = list(value)707172