summaryrefslogtreecommitdiff
path: root/dns
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2014-06-21 08:55:09 -0700
committerBob Halley <halley@dnspython.org>2014-08-31 16:46:08 -0700
commit4590c7defcf91e6168c927c36e1efded0ee96a36 (patch)
tree796e7a4e32cd58d8ca2edf48828e97b12de24b72 /dns
parentd0359473bf0f42e77f0fa29cfafd40fa6070e72b (diff)
downloaddnspython-4590c7defcf91e6168c927c36e1efded0ee96a36.tar.gz
Add dns.zone.to_text() convenience method.
Diffstat (limited to 'dns')
-rw-r--r--dns/zone.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/dns/zone.py b/dns/zone.py
index 04c1ecf..c1b0223 100644
--- a/dns/zone.py
+++ b/dns/zone.py
@@ -18,6 +18,7 @@
from __future__ import generators
import builtins
+import io
import re
import sys
@@ -491,6 +492,27 @@ class Zone(object):
if want_close:
f.close()
+ def to_text(self, sorted=True, relativize=True, nl=None):
+ """Return a zone's text as though it were written to a file.
+
+ @param sorted: if True, the file will be written with the
+ names sorted in DNSSEC order from least to greatest. Otherwise
+ the names will be written in whatever order they happen to have
+ in the zone's dictionary.
+ @param relativize: if True, domain names in the output will be
+ relativized to the zone's origin (if possible).
+ @type relativize: bool
+ @param nl: The end of line string. If not specified, the
+ output will use the platform's native end-of-line marker (i.e.
+ LF on POSIX, CRLF on Windows, CR on Macintosh).
+ @type nl: string or None
+ """
+ temp_buffer = io.StringIO()
+ self.to_file(temp_buffer, sorted, relativize, nl)
+ return_value = temp_buffer.getvalue()
+ temp_buffer.close()
+ return return_value
+
def check_origin(self):
"""Do some simple checking of the zone's origin.