diff options
author | Bob Halley <halley@dnspython.org> | 2005-11-17 23:00:17 +0000 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2005-11-17 23:00:17 +0000 |
commit | f3fa34269e0c14d9d47ee6d9bc3c3bb8e208bcde (patch) | |
tree | f1ebfa94cda4424e7b22d95ee5818ab8014b644a | |
parent | d05453d7e4c44fcaf60697f58948d2e5df1a53a4 (diff) | |
download | dnspython-f3fa34269e0c14d9d47ee6d9bc3c3bb8e208bcde.tar.gz |
allow origin node sanity checks to be disabled
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | dns/zone.py | 28 |
2 files changed, 26 insertions, 7 deletions
@@ -1,3 +1,8 @@ +2005-11-17 Bob Halley <halley@dnspython.org> + + * dns/zone.py: Sanity checks of the zone's origin node can now + be disabled. + 2005-11-12 Bob Halley <halley@dnspython.org> * dns/name.py: Preliminary Unicode support has been added for diff --git a/dns/zone.py b/dns/zone.py index 085a6a1..6c3de88 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -539,10 +539,13 @@ class _MasterReader(object): (None if no $INCLUDE is active). @ivar allow_include: is $INCLUDE allowed? @type allow_include: bool + @ivar check_origin: should sanity checks of the origin node be done? + The default is True. + @type check_origin: bool """ def __init__(self, tok, origin, rdclass, relativize, zone_factory=Zone, - allow_include=False): + allow_include=False, check_origin=True): if isinstance(origin, (str, unicode)): origin = dns.name.from_text(origin) self.tok = tok @@ -554,6 +557,7 @@ class _MasterReader(object): self.saved_state = [] self.current_file = None self.allow_include = allow_include + self.check_origin = check_origin def _eat_line(self): while 1: @@ -713,10 +717,12 @@ class _MasterReader(object): "%s:%d: %s" % (filename, line_number, detail) # Now that we're done reading, do some basic checking of the zone. - self.zone.check_origin() + if self.check_origin: + self.zone.check_origin() def from_text(text, origin, rdclass = dns.rdataclass.IN, relativize = True, - zone_factory=Zone, filename=None, allow_include=False): + zone_factory=Zone, filename=None, allow_include=False, + check_origin=True): """Build a zone object from a master file format string. @param text: the master file format input @@ -731,9 +737,12 @@ def from_text(text, origin, rdclass = dns.rdataclass.IN, relativize = True, @type zone_factory: function returning a Zone @param filename: The filename to emit when describing where an error occurred; the default is '<string>'. + @type filename: string @param allow_include: is $INCLUDE allowed? @type allow_include: bool - @type filename: string + @param check_origin: should sanity checks of the origin node be done? + The default is True. + @type check_origin: bool @raises dns.zone.NoSOA: No SOA RR was found at the zone origin @raises dns.zone.NoNS: No NS RRset was found at the zone origin @rtype: dns.zone.Zone object @@ -747,12 +756,14 @@ def from_text(text, origin, rdclass = dns.rdataclass.IN, relativize = True, filename = '<string>' tok = dns.tokenizer.Tokenizer(text, filename) reader = _MasterReader(tok, origin, rdclass, relativize, zone_factory, - allow_include=allow_include) + allow_include=allow_include, + check_origin=check_origin) reader.read() return reader.zone def from_file(f, origin, rdclass = dns.rdataclass.IN, relativize = True, - zone_factory=Zone, filename=None, allow_include=True): + zone_factory=Zone, filename=None, allow_include=True, + check_origin=True): """Read a master file and build a zone object. @param f: file or string. If I{f} is a string, it is treated @@ -771,6 +782,9 @@ def from_file(f, origin, rdclass = dns.rdataclass.IN, relativize = True, @type filename: string @param allow_include: is $INCLUDE allowed? @type allow_include: bool + @param check_origin: should sanity checks of the origin node be done? + The default is True. + @type check_origin: bool @raises dns.zone.NoSOA: No SOA RR was found at the zone origin @raises dns.zone.NoNS: No NS RRset was found at the zone origin @rtype: dns.zone.Zone object @@ -795,7 +809,7 @@ def from_file(f, origin, rdclass = dns.rdataclass.IN, relativize = True, try: z = from_text(f, origin, rdclass, relativize, zone_factory, - filename, allow_include) + filename, allow_include, check_origin) finally: if want_close: f.close() |