Wrap ``body`` in an ``if ({toggle})`` guard and return the indented emission. ``extra_cond=None``: ``if ({toggle}) {body}`` ``extra_cond`` + first=False: ``if ({toggle} && {extra_cond}) {body}`` ``extra_cond`` + first=True: ``if (({extra_cond}) && {tog
(toggle: str, body: str,
extra_cond: Optional[str] = None,
extra_cond_first: bool = False,
multiline: bool = False)
| 259 | |
| 260 | |
| 261 | def _guarded_export(toggle: str, body: str, |
| 262 | extra_cond: Optional[str] = None, |
| 263 | extra_cond_first: bool = False, |
| 264 | multiline: bool = False) -> str: |
| 265 | """Wrap ``body`` in an ``if ({toggle})`` guard and return the indented |
| 266 | emission. |
| 267 | |
| 268 | ``extra_cond=None``: ``if ({toggle}) {body}`` |
| 269 | ``extra_cond`` + first=False: ``if ({toggle} && {extra_cond}) {body}`` |
| 270 | ``extra_cond`` + first=True: ``if (({extra_cond}) && {toggle}) {body}`` |
| 271 | |
| 272 | ``multiline=True``: emit a braced block. ``body`` is dropped verbatim |
| 273 | inside the braces (caller controls inner indent — the helper does |
| 274 | NOT auto-indent each line so existing multi-line bodies migrate |
| 275 | byte-identically). Use for blocks that were previously hand-rolled |
| 276 | as ``if ({toggle})\\n{{\\n<body>\\n}}\\n``. |
| 277 | """ |
| 278 | if extra_cond is None: |
| 279 | cond = toggle |
| 280 | elif extra_cond_first: |
| 281 | cond = f"({extra_cond}) && {toggle}" |
| 282 | else: |
| 283 | cond = f"{toggle} && {extra_cond}" |
| 284 | if multiline: |
| 285 | return f" if ({cond})\n {{\n{body} }}\n" |
| 286 | return f" if ({cond}) {body}\n" |
| 287 | |
| 288 | |
| 289 | # `_UEType`, `_UE_TYPE_INFO`, and `_attr_default_value` live in |
no outgoing calls