|
24 | 24 | _rust_dicttoxml = None |
25 | 25 |
|
26 | 26 | try: |
27 | | - from json2xml_rs import dicttoxml as _rust_dicttoxml # type: ignore[import-not-found] |
28 | | - from json2xml_rs import escape_xml_py as rust_escape_xml # type: ignore[import-not-found] |
29 | | - from json2xml_rs import wrap_cdata_py as rust_wrap_cdata # type: ignore[import-not-found] |
30 | | - _USE_RUST = True |
31 | | - LOG.debug("Using Rust backend for dicttoxml") |
| 27 | + from json2xml_rs import dicttoxml as _rust_dicttoxml # type: ignore[import-not-found] # pragma: no cover |
| 28 | + from json2xml_rs import escape_xml_py as rust_escape_xml # type: ignore[import-not-found] # pragma: no cover |
| 29 | + from json2xml_rs import wrap_cdata_py as rust_wrap_cdata # type: ignore[import-not-found] # pragma: no cover |
| 30 | + _USE_RUST = True # pragma: no cover |
| 31 | + LOG.debug("Using Rust backend for dicttoxml") # pragma: no cover |
32 | 32 | except ImportError: # pragma: no cover |
33 | 33 | LOG.debug("Rust backend not available, using pure Python") |
34 | 34 | rust_escape_xml = None |
@@ -95,7 +95,7 @@ def dicttoxml( |
95 | 95 | if not needs_python and isinstance(obj, dict): |
96 | 96 | needs_python = _has_special_keys(obj) |
97 | 97 |
|
98 | | - if _USE_RUST and not needs_python and _rust_dicttoxml is not None: |
| 98 | + if _USE_RUST and not needs_python and _rust_dicttoxml is not None: # pragma: no cover |
99 | 99 | # Use fast Rust implementation |
100 | 100 | return _rust_dicttoxml( |
101 | 101 | obj, |
@@ -143,14 +143,14 @@ def _has_special_keys(obj: Any) -> bool: |
143 | 143 | # Re-export commonly used functions |
144 | 144 | def escape_xml(s: str) -> str: |
145 | 145 | """Escape special XML characters in a string.""" |
146 | | - if _USE_RUST and rust_escape_xml is not None: |
| 146 | + if _USE_RUST and rust_escape_xml is not None: # pragma: no cover |
147 | 147 | return rust_escape_xml(s) |
148 | 148 | return _py_dicttoxml.escape_xml(s) |
149 | 149 |
|
150 | 150 |
|
151 | 151 | def wrap_cdata(s: str) -> str: |
152 | 152 | """Wrap a string in a CDATA section.""" |
153 | | - if _USE_RUST and rust_wrap_cdata is not None: |
| 153 | + if _USE_RUST and rust_wrap_cdata is not None: # pragma: no cover |
154 | 154 | return rust_wrap_cdata(s) |
155 | 155 | return _py_dicttoxml.wrap_cdata(s) |
156 | 156 |
|
|
0 commit comments