diff options
author | Bob Halley <halley@dnspython.org> | 2020-07-18 13:07:04 -0700 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2020-07-20 13:41:22 -0700 |
commit | 7d81222f3e7f169333c9e88611cf1dedb12828be (patch) | |
tree | 8cb8acd06467e474be184483688ed3e61a2e117e /dns/rdataset.py | |
parent | a7604f891512ca99141c2068a4c57af45db62880 (diff) | |
download | dnspython-comments.tar.gz |
a way of doing commentscomments
Diffstat (limited to 'dns/rdataset.py')
-rw-r--r-- | dns/rdataset.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/dns/rdataset.py b/dns/rdataset.py index 660415e..8e70a08 100644 --- a/dns/rdataset.py +++ b/dns/rdataset.py @@ -176,7 +176,7 @@ class Rdataset(dns.set.Set): return not self.__eq__(other) def to_text(self, name=None, origin=None, relativize=True, - override_rdclass=None, **kw): + override_rdclass=None, want_comments=False, **kw): """Convert the rdataset into DNS master file format. See ``dns.name.Name.choose_relativity`` for more information @@ -194,6 +194,9 @@ class Rdataset(dns.set.Set): *relativize*, a ``bool``. If ``True``, names will be relativized to *origin*. + + *want_comments*, a ``bool``. If ``True``, emit comments for rdata + which have them. The default is ``False``. """ if name is not None: @@ -219,11 +222,16 @@ class Rdataset(dns.set.Set): dns.rdatatype.to_text(self.rdtype))) else: for rd in self: - s.write('%s%s%d %s %s %s\n' % + extra = '' + if want_comments: + if rd.rdcomment: + extra = f' ;{rd.rdcomment}' + s.write('%s%s%d %s %s %s%s\n' % (ntext, pad, self.ttl, dns.rdataclass.to_text(rdclass), dns.rdatatype.to_text(self.rdtype), rd.to_text(origin=origin, relativize=relativize, - **kw))) + **kw), + extra)) # # We strip off the final \n for the caller's convenience in printing # |