Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions stubs/xmltodict/@tests/test_cases/check_postprocessor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations

import xmltodict
from xmltodict import _AttrDict, _AttrValue


# XML post-processor that eats all `b` elements
def b_eater(path: list[tuple[str, _AttrDict | None]], key: str, value: _AttrValue) -> tuple[str, _AttrValue] | None:
if key == "b":
return None # discard the node entirely
return key, value


xmltodict.parse("<a><b/><c><b/></c></a>", postprocessor=b_eater)
# returns a tree of just <a><c/></a>
8 changes: 5 additions & 3 deletions stubs/xmltodict/xmltodict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _DictSAXHandler:
cdata_key: str
force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool]
cdata_separator: str
postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None
postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue] | None] | None
dict_constructor: type
strip_whitespace: bool
namespace_separator: str
Expand All @@ -37,7 +37,9 @@ class _DictSAXHandler:
cdata_key: str = "#text",
force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] = False,
cdata_separator: str = "",
postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None = None,
postprocessor: (
Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue] | None] | None
) = None,
dict_constructor: type = ...,
strip_whitespace: bool = True,
namespace_separator: str = ":",
Expand Down Expand Up @@ -68,7 +70,7 @@ def parse(
cdata_key: str = "#text",
force_cdata: bool | Container[str] | Callable[[tuple[str, _AttrDict | None], str, str], bool] = False,
cdata_separator: str = "",
postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue]] | None = None,
postprocessor: Callable[[list[tuple[str, _AttrDict | None]], str, _AttrValue], tuple[str, _AttrValue] | None] | None = None,
dict_constructor: type = ...,
strip_whitespace: bool = True,
namespaces: Mapping[str, str | None] | None = None,
Expand Down
Loading