Parse a component ID and return it as a dict if it contains a wildcard. Accepts string (JSON-encoded) or dict IDs. Returns ``None`` if the ID is not a wildcard pattern. Example:: >>> parse_wildcard_id('{"type":"input","index":["ALL"]}') {"type": "input", "index": ["ALL
(pid: Any)
| 145 | |
| 146 | |
| 147 | def parse_wildcard_id(pid: Any) -> dict | None: |
| 148 | """Parse a component ID and return it as a dict if it contains a wildcard. |
| 149 | |
| 150 | Accepts string (JSON-encoded) or dict IDs. Returns ``None`` |
| 151 | if the ID is not a wildcard pattern. |
| 152 | |
| 153 | Example:: |
| 154 | |
| 155 | >>> parse_wildcard_id('{"type":"input","index":["ALL"]}') |
| 156 | {"type": "input", "index": ["ALL"]} |
| 157 | >>> parse_wildcard_id("my-dropdown") |
| 158 | None |
| 159 | """ |
| 160 | if isinstance(pid, str) and pid.startswith("{"): |
| 161 | try: |
| 162 | pid = json.loads(pid) |
| 163 | except (json.JSONDecodeError, ValueError): |
| 164 | return None |
| 165 | if not isinstance(pid, dict): |
| 166 | return None |
| 167 | for v in pid.values(): |
| 168 | if isinstance(v, list) and len(v) == 1 and v[0] in _WILDCARD_VALUES: |
| 169 | return pid |
| 170 | return None |
| 171 | |
| 172 | |
| 173 | def find_matching_components(pattern: dict) -> list[Component]: |
no outgoing calls
searching dependent graphs…