Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/turbohtml/traverse.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

22 statements  

1""" 

2turbohtml.traverse: the DOM Living Standard traversal objects. 

3 

4:class:`~turbohtml.TreeWalker` is a movable cursor over a subtree; :class:`~turbohtml.NodeIterator` is a flat 

5forward/backward view of the same nodes. Both are C types that pair a ``what_to_show`` bitmask with an optional 

6``filter`` callback; :class:`NodeFilter` collects the named constants for both -- the ``SHOW_*`` bits and the 

7``FILTER_*`` verdicts -- so a filter reads as it would against jsdom's ``NodeFilter``. 

8 

9The one turbohtml spelling difference from the DOM: methods are snake_case (``next_node``, ``current_node``) and the 

10constructor takes ``root`` positionally with ``what_to_show`` and ``filter`` as keywords, rather than the DOM's 

11``document.createTreeWalker(root, whatToShow, filter)`` factory. 

12""" 

13 

14from __future__ import annotations 

15 

16from typing import Final 

17 

18from ._html import NodeIterator, TreeWalker 

19 

20__all__ = ["NodeFilter", "NodeIterator", "TreeWalker"] 

21 

22 

23class NodeFilter: 

24 """ 

25 The whatToShow bits and filter verdicts a :class:`TreeWalker` or :class:`NodeIterator` reads. 

26 

27 The ``SHOW_*`` constants are the ``what_to_show`` bitmask -- OR them to consider several node types, or use 

28 ``SHOW_ALL``. A ``filter`` callback returns one of the ``FILTER_*`` verdicts: ``FILTER_ACCEPT`` yields the node, 

29 ``FILTER_REJECT`` skips it and (in a :class:`TreeWalker`) its whole subtree, and ``FILTER_SKIP`` skips only the 

30 node. A :class:`NodeIterator` has no subtree to skip, so it treats reject and skip alike. 

31 """ 

32 

33 SHOW_ALL: Final = 0xFFFFFFFF 

34 SHOW_ELEMENT: Final = 0x1 

35 SHOW_ATTRIBUTE: Final = 0x2 

36 SHOW_TEXT: Final = 0x4 

37 SHOW_CDATA_SECTION: Final = 0x8 

38 SHOW_ENTITY_REFERENCE: Final = 0x10 

39 SHOW_ENTITY: Final = 0x20 

40 SHOW_PROCESSING_INSTRUCTION: Final = 0x40 

41 SHOW_COMMENT: Final = 0x80 

42 SHOW_DOCUMENT: Final = 0x100 

43 SHOW_DOCUMENT_TYPE: Final = 0x200 

44 SHOW_DOCUMENT_FRAGMENT: Final = 0x400 

45 SHOW_NOTATION: Final = 0x800 

46 

47 FILTER_ACCEPT: Final = 1 

48 FILTER_REJECT: Final = 2 

49 FILTER_SKIP: Final = 3