Return a node matching the input key.
(self, key: str)
| 421 | self.cache[key] = node |
| 422 | |
| 423 | def get_node(self, key: str) -> Node: |
| 424 | """Return a node matching the input key.""" |
| 425 | node = self.cache.pop(key, None) |
| 426 | if node is not None: |
| 427 | if node._v_isopen: |
| 428 | self.cache_node(node, key) |
| 429 | return node |
| 430 | else: |
| 431 | # this should not happen |
| 432 | warnings.warn("a closed node found in the cache: ``%s``" % key) |
| 433 | |
| 434 | if key in self.registry: |
| 435 | node = self.registry[key] |
| 436 | if node is None: |
| 437 | # this should not happen since WeakValueDictionary drops all |
| 438 | # dead weakrefs |
| 439 | warnings.warn( |
| 440 | "None is stored in the registry for key: " "``%s``" % key |
| 441 | ) |
| 442 | elif node._v_isopen: |
| 443 | self.cache_node(node, key) |
| 444 | return node |
| 445 | else: |
| 446 | # this should not happen |
| 447 | warnings.warn( |
| 448 | "a closed node found in the registry: " "``%s``" % key |
| 449 | ) |
| 450 | del self.registry[key] |
| 451 | node = None |
| 452 | |
| 453 | if self.node_factory: |
| 454 | node = self.node_factory(key) |
| 455 | self.cache_node(node, key) |
| 456 | |
| 457 | return node |
| 458 | |
| 459 | def rename_node(self, oldkey: str, newkey: str) -> None: |
| 460 | """Rename a node.""" |
nothing calls this directly
no test coverage detected