(self, args: dict[str]={})
| 21 | self.init_time = time.time() - stt |
| 22 | |
| 23 | def parse_args(self, args: dict[str]={}) -> None: |
| 24 | def attr_check(attr, type_model='str'): |
| 25 | if attr is None: |
| 26 | return False |
| 27 | attr_type = type(attr) |
| 28 | if attr_type != type(type_model): |
| 29 | return False |
| 30 | if attr_type == type('str') and len(attr) == 0: |
| 31 | return False |
| 32 | return True |
| 33 | |
| 34 | args = {} if args is None else args |
| 35 | |
| 36 | # [Position] use_pos: False -> use full page, otherwise use window_size |
| 37 | use_position = args.get('use_position', False) |
| 38 | window_size = args.get('window_size', None) |
| 39 | rect = args.get('rect_dict', None) |
| 40 | if use_position: |
| 41 | if not attr_check(window_size, ()): |
| 42 | raise ValueError('window_size must be set when use_position is True') |
| 43 | if not attr_check(rect, {}): |
| 44 | raise ValueError('rect_dict must be set when use_position is True') |
| 45 | |
| 46 | if not attr_check(rect, {}): |
| 47 | rect = {} |
| 48 | |
| 49 | # [Label] for vimium is temp_clickable_label, otherwise keep all of it |
| 50 | label_attr = args.get('label_attr', '') |
| 51 | get_new_label = args.get('regenerate_label', False) |
| 52 | label_method = args.get('label_generator', None) |
| 53 | regen_label = not attr_check(label_method) |
| 54 | |
| 55 | # [id] for mind2web is backend_node_id, for normal website use our method |
| 56 | id_attr = args.get('id_attr', '') |
| 57 | regen_id = not attr_check(id_attr) |
| 58 | |
| 59 | if regen_id: |
| 60 | id_attr = 'temp_id' |
| 61 | |
| 62 | # [attributes] |
| 63 | keep_attrs = args.get('attr_list', []) |
| 64 | if not attr_check(keep_attrs, []): |
| 65 | keep_attrs = [] |
| 66 | |
| 67 | # [Tags] for clickable elem, keep: must keep, obs: keep if follow specific rule |
| 68 | parent_chain = args.get('parent_chain', False) |
| 69 | keep_elem = args.get('keep_elem', []) |
| 70 | obs_elem = args.get('obs_elem', []) |
| 71 | |
| 72 | # sanity check |
| 73 | self.set_args(use_position, window_size, rect, label_attr, id_attr, keep_attrs, keep_elem, obs_elem, parent_chain, get_new_label) |
| 74 | |
| 75 | # [Prompt] |
| 76 | prompt = args.get('prompt', None) |
| 77 | self.prompt = HtmlPrompt(prompt) |
| 78 | |
| 79 | # traverse and get special data |
| 80 | if regen_id or regen_label: |
no test coverage detected