(node: html.HtmlElement, keep: list[str]=[], obs: list[str]=[],
parent_chain: bool=False, get_new_label: bool=False, par_keep: bool=False)
| 198 | return True |
| 199 | |
| 200 | def _dfs(node: html.HtmlElement, keep: list[str]=[], obs: list[str]=[], |
| 201 | parent_chain: bool=False, get_new_label: bool=False, par_keep: bool=False) -> (str, dict[str]): |
| 202 | # basic information |
| 203 | bid = node.attrib.get(self.id_attr, '') |
| 204 | tag = node.tag |
| 205 | label = node.attrib.get(self.label_attr, '') |
| 206 | |
| 207 | # element which is keeped equivalent to visible |
| 208 | visible = is_visible(node, bid) |
| 209 | in_keep_list = bid in keep |
| 210 | in_obs_list = (bid in obs or len(label) > 0) and visible |
| 211 | keep_element = in_keep_list or in_obs_list or visible or par_keep |
| 212 | |
| 213 | # mark label |
| 214 | bids2label, labeled_elems = {}, [] |
| 215 | have_label = False |
| 216 | if in_keep_list or in_obs_list: |
| 217 | if label is None or len(label) == 0 or get_new_label: |
| 218 | label = self.identifier.generate() |
| 219 | node.attrib[self.label_attr] = label |
| 220 | bids2label[bid] = label |
| 221 | bids2label[label] = bid |
| 222 | have_label = True |
| 223 | |
| 224 | # get text or alt_text of current element |
| 225 | text = get_text(node.text) |
| 226 | |
| 227 | classes = {} |
| 228 | # keep attributes if needed |
| 229 | keep_all_attrs = len(self.keep_attrs) == 0 |
| 230 | keep_attrs = node.attrib.keys() if keep_all_attrs else self.keep_attrs |
| 231 | |
| 232 | # traverse attributes |
| 233 | for attr in keep_attrs: |
| 234 | if attr not in node.attrib or not check_attr(attr, node): |
| 235 | continue |
| 236 | if attr in [self.id_attr, self.label_attr]: |
| 237 | continue |
| 238 | val = get_text(node.attrib[attr]) |
| 239 | if len(val) > 0 or keep_all_attrs: |
| 240 | classes[attr] = val |
| 241 | |
| 242 | have_text = len(text) > 0 or len(classes) > 0 |
| 243 | |
| 244 | parts = [] |
| 245 | clickable_count = 0 |
| 246 | children = node.getchildren() |
| 247 | for child in children: |
| 248 | cres, cmsg = _dfs(child, keep, obs, parent_chain, get_new_label) |
| 249 | clickable_count += 1 if cmsg.get('have_clickable', False) else 0 |
| 250 | bids2label.update(cmsg.get('bids2label', {})) |
| 251 | labeled_elems.extend(cmsg.get('label_element', [])) |
| 252 | if len(cres) != 0: |
| 253 | parts.append(cres) |
| 254 | |
| 255 | dom = self.prompt.subtree_constructor(parts) |
| 256 | |
| 257 | # remove <text|> if all children are text |
nothing calls this directly
no test coverage detected