• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Copyright (c) 2024 Huawei Device Co., Ltd.
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9    http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Description: Python CDP Debugger.
18"""
19
20from dataclasses import dataclass
21from typing import Optional, List
22
23
24@dataclass
25class BreakLocationUrl:
26    url: str
27    line_number: int
28    column_number: Optional[int] = 0
29
30    def to_json(self):
31        json = {'url': self.url,
32                'lineNumber': self.line_number,
33                'columnNumber': self.column_number}
34        return json
35
36
37def enable(max_scripts_cache_size: Optional[float] = None):
38    command = {'method': 'Debugger.enable'}
39    if max_scripts_cache_size:
40        command['params'] = {'maxScriptsCacheSize': max_scripts_cache_size}
41    return command
42
43
44def resume():
45    command = {'method': 'Debugger.resume'}
46    return command
47
48
49def remove_breakpoints_by_url(url: str):
50    command = {'method': 'Debugger.removeBreakpointsByUrl',
51               'params': {'url': url}}
52    return command
53
54
55def get_possible_and_set_breakpoint_by_url(locations: List[BreakLocationUrl]):
56    params = {'locations': []}
57    for location in locations:
58        params['locations'].append(location.to_json())
59    command = {'method': 'Debugger.getPossibleAndSetBreakpointByUrl',
60               'params': params}
61    return command
62
63
64def step_over():
65    command = {'method': 'Debugger.stepOver'}
66    return command
67
68
69def disable():
70    command = {'method': 'Debugger.disable'}
71    return command
72