A Node is a set of rdatasets. A node is either a CNAME node or an "other data" node. A CNAME node contains only CNAME, KEY, NSEC, and NSEC3 rdatasets along with their covering RRSIG rdatasets. An "other data" node contains any rdataset other than a CNAME or RRSIG(CNAME) rdataset.
| 69 | |
| 70 | |
| 71 | class Node: |
| 72 | """A Node is a set of rdatasets. |
| 73 | |
| 74 | A node is either a CNAME node or an "other data" node. A CNAME |
| 75 | node contains only CNAME, KEY, NSEC, and NSEC3 rdatasets along with their |
| 76 | covering RRSIG rdatasets. An "other data" node contains any |
| 77 | rdataset other than a CNAME or RRSIG(CNAME) rdataset. When |
| 78 | changes are made to a node, the CNAME or "other data" state is |
| 79 | always consistent with the update, i.e. the most recent change |
| 80 | wins. For example, if you have a node which contains a CNAME |
| 81 | rdataset, and then add an MX rdataset to it, then the CNAME |
| 82 | rdataset will be deleted. Likewise if you have a node containing |
| 83 | an MX rdataset and add a CNAME rdataset, the MX rdataset will be |
| 84 | deleted. |
| 85 | """ |
| 86 | |
| 87 | __slots__ = ["rdatasets"] |
| 88 | |
| 89 | def __init__(self): |
| 90 | # the set of rdatasets, represented as a list. |
| 91 | self.rdatasets = [] |
| 92 | |
| 93 | def to_text(self, name: dns.name.Name, **kw: Dict[str, Any]) -> str: |
| 94 | """Convert a node to text format. |
| 95 | |
| 96 | Each rdataset at the node is printed. Any keyword arguments |
| 97 | to this method are passed on to the rdataset's to_text() method. |
| 98 | |
| 99 | *name*, a ``dns.name.Name``, the owner name of the |
| 100 | rdatasets. |
| 101 | |
| 102 | Returns a ``str``. |
| 103 | |
| 104 | """ |
| 105 | |
| 106 | s = io.StringIO() |
| 107 | for rds in self.rdatasets: |
| 108 | if len(rds) > 0: |
| 109 | s.write(rds.to_text(name, **kw)) # type: ignore[arg-type] |
| 110 | s.write("\n") |
| 111 | return s.getvalue()[:-1] |
| 112 | |
| 113 | def __repr__(self): |
| 114 | return "<DNS node " + str(id(self)) + ">" |
| 115 | |
| 116 | def __eq__(self, other): |
| 117 | # |
| 118 | # This is inefficient. Good thing we don't need to do it much. |
| 119 | # |
| 120 | for rd in self.rdatasets: |
| 121 | if rd not in other.rdatasets: |
| 122 | return False |
| 123 | for rd in other.rdatasets: |
| 124 | if rd not in self.rdatasets: |
| 125 | return False |
| 126 | return True |
| 127 | |
| 128 | def __ne__(self, other): |
no outgoing calls
searching dependent graphs…