Path: blob/trunk/py/selenium/webdriver/common/bidi/log.py
4015 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.16from __future__ import annotations1718from dataclasses import dataclass19from typing import Any202122class LogEntryAdded:23event_class = "log.entryAdded"2425@classmethod26def from_json(cls, json: dict[str, Any]) -> ConsoleLogEntry | JavaScriptLogEntry | None:27if json["type"] == "console":28return ConsoleLogEntry.from_json(json)29elif json["type"] == "javascript":30return JavaScriptLogEntry.from_json(json)31return None323334@dataclass35class ConsoleLogEntry:36level: str37text: str38timestamp: str39method: str40args: list[dict[str, Any]]41type_: str4243@classmethod44def from_json(cls, json: dict[str, Any]) -> ConsoleLogEntry:45return cls(46level=json["level"],47text=json["text"],48timestamp=json["timestamp"],49method=json["method"],50args=json["args"],51type_=json["type"],52)535455@dataclass56class JavaScriptLogEntry:57level: str58text: str59timestamp: str60stacktrace: dict[str, Any]61type_: str6263@classmethod64def from_json(cls, json: dict[str, Any]) -> JavaScriptLogEntry:65return cls(66level=json["level"],67text=json["text"],68timestamp=json["timestamp"],69stacktrace=json["stackTrace"],70type_=json["type"],71)727374class LogLevel:75"""Represents log level."""7677DEBUG = "debug"78INFO = "info"79WARN = "warn"80ERROR = "error"818283