Remove tree Elements with 'api' attributes matching apiName. tree - Element at the root of the hierarchy to strip. Only its children can actually be removed, not the tree itself. apiName - string which much match a command-separated component of the 'api' att
(tree, apiName, actuallyDelete = True)
| 272 | |
| 273 | |
| 274 | def stripNonmatchingAPIs(tree, apiName, actuallyDelete = True): |
| 275 | """Remove tree Elements with 'api' attributes matching apiName. |
| 276 | |
| 277 | tree - Element at the root of the hierarchy to strip. Only its |
| 278 | children can actually be removed, not the tree itself. |
| 279 | apiName - string which much match a command-separated component of |
| 280 | the 'api' attribute. |
| 281 | actuallyDelete - only delete matching elements if True.""" |
| 282 | |
| 283 | stack = deque() |
| 284 | stack.append(tree) |
| 285 | |
| 286 | while len(stack) > 0: |
| 287 | parent = stack.pop() |
| 288 | |
| 289 | for child in parent.findall('*'): |
| 290 | api = child.get('api') |
| 291 | |
| 292 | if apiNameMatch(apiName, api): |
| 293 | # Add child to the queue |
| 294 | stack.append(child) |
| 295 | elif not apiNameMatch(apiName, api): |
| 296 | # Child does not match requested api. Remove it. |
| 297 | if actuallyDelete: |
| 298 | parent.remove(child) |
| 299 | |
| 300 | |
| 301 | class BaseInfo: |
no test coverage detected