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 Runtime. 18""" 19 20from dataclasses import dataclass 21from typing import Optional 22 23 24@dataclass 25class GetPropertiesParams: 26 object_id: str = "" 27 own_properties: bool = True 28 accessor_properties_only: bool = False 29 generate_preview: bool = True 30 non_indexed_properties_only: Optional[bool] = None 31 32 33def enable(): 34 command = {'method': 'Runtime.enable'} 35 return command 36 37 38def run_if_waiting_for_debugger(): 39 command = {'method': 'Runtime.runIfWaitingForDebugger'} 40 return command 41 42 43def get_properties(params: GetPropertiesParams): 44 command = {'method': 'Runtime.getProperties', 45 'params': {'objectId': params.object_id, 46 'ownProperties': params.own_properties, 47 'accessorPropertiesOnly': params.accessor_properties_only, 48 'generatePreview': params.generate_preview}} 49 if params.non_indexed_properties_only is not None: 50 command['params']['nonIndexedPropertiesOnly'] = params.non_indexed_properties_only 51 return command 52 53 54def get_heap_usage(): 55 return {'method': 'Runtime.getHeapUsage'}