zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: Log
from __future__ import annotations
from .util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
from . import network
from . import runtime
 
 
@dataclass
class LogEntry:
    '''
    Log entry.
    '''
    #: Log entry source.
    source: str
 
    #: Log entry severity.
    level: str
 
    #: Logged text.
    text: str
 
    #: Timestamp when this entry was added.
    timestamp: runtime.Timestamp
 
    category: typing.Optional[str] = None
 
    #: URL of the resource if known.
    url: typing.Optional[str] = None
 
    #: Line number in the resource.
    line_number: typing.Optional[int] = None
 
    #: JavaScript stack trace.
    stack_trace: typing.Optional[runtime.StackTrace] = None
 
    #: Identifier of the network request associated with this entry.
    network_request_id: typing.Optional[network.RequestId] = None
 
    #: Identifier of the worker associated with this entry.
    worker_id: typing.Optional[str] = None
 
    #: Call arguments.
    args: typing.Optional[typing.List[runtime.RemoteObject]] = None
 
    def to_json(self):
        json = dict()
        json['source'] = self.source
        json['level'] = self.level
        json['text'] = self.text
        json['timestamp'] = self.timestamp.to_json()
        if self.category is not None:
            json['category'] = self.category
        if self.url is not None:
            json['url'] = self.url
        if self.line_number is not None:
            json['lineNumber'] = self.line_number
        if self.stack_trace is not None:
            json['stackTrace'] = self.stack_trace.to_json()
        if self.network_request_id is not None:
            json['networkRequestId'] = self.network_request_id.to_json()
        if self.worker_id is not None:
            json['workerId'] = self.worker_id
        if self.args is not None:
            json['args'] = [i.to_json() for i in self.args]
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            source=str(json['source']),
            level=str(json['level']),
            text=str(json['text']),
            timestamp=runtime.Timestamp.from_json(json['timestamp']),
            category=str(json['category']) if 'category' in json else None,
            url=str(json['url']) if 'url' in json else None,
            line_number=int(json['lineNumber']) if 'lineNumber' in json else None,
            stack_trace=runtime.StackTrace.from_json(json['stackTrace']) if 'stackTrace' in json else None,
            network_request_id=network.RequestId.from_json(json['networkRequestId']) if 'networkRequestId' in json else None,
            worker_id=str(json['workerId']) if 'workerId' in json else None,
            args=[runtime.RemoteObject.from_json(i) for i in json['args']] if 'args' in json else None,
        )
 
 
@dataclass
class ViolationSetting:
    '''
    Violation configuration setting.
    '''
    #: Violation type.
    name: str
 
    #: Time threshold to trigger upon.
    threshold: float
 
    def to_json(self):
        json = dict()
        json['name'] = self.name
        json['threshold'] = self.threshold
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            name=str(json['name']),
            threshold=float(json['threshold']),
        )
 
 
def clear() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Clears the log.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Log.clear',
    }
    json = yield cmd_dict
 
 
def disable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Disables log domain, prevents further log entries from being reported to the client.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Log.disable',
    }
    json = yield cmd_dict
 
 
def enable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Enables log domain, sends the entries collected so far to the client by means of the
    ``entryAdded`` notification.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Log.enable',
    }
    json = yield cmd_dict
 
 
def start_violations_report(
        config: typing.List[ViolationSetting]
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    start violation reporting.
 
    :param config: Configuration for violations.
    '''
    params: T_JSON_DICT = dict()
    params['config'] = [i.to_json() for i in config]
    cmd_dict: T_JSON_DICT = {
        'method': 'Log.startViolationsReport',
        'params': params,
    }
    json = yield cmd_dict
 
 
def stop_violations_report() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Stop violation reporting.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Log.stopViolationsReport',
    }
    json = yield cmd_dict
 
 
@event_class('Log.entryAdded')
@dataclass
class EntryAdded:
    '''
    Issued when new message was logged.
    '''
    #: The entry.
    entry: LogEntry
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> EntryAdded:
        return cls(
            entry=LogEntry.from_json(json['entry'])
        )