summaryrefslogtreecommitdiff
path: root/dns/tokenizer.py
diff options
context:
space:
mode:
authorBrian Wellington <bwelling@xbill.org>2020-03-18 16:44:09 -0700
committerBrian Wellington <bwelling@xbill.org>2020-03-18 16:44:09 -0700
commitcee00834c8ef0c1a0bebbeb98f5e0c97d39ad0d4 (patch)
tree930da1b29884daa1a5d38d63387b49fb41181ced /dns/tokenizer.py
parent41ca1be22dad341709a3856f34fe63aa46da1d1b (diff)
downloaddnspython-cee00834c8ef0c1a0bebbeb98f5e0c97d39ad0d4.tar.gz
Add relativize_to to from_text().
When calling from_text, the zone code needs to apply the current origin (which may or may not be the zone origin, if sub-zone $ORIGIN statements are present), and may also want to relativize the contents to the zone origin. Previously, this was done by explicitly reading records as absolute, and then relativizing them laster. With this change, the work is moved to the tokenizer. This gets rid of the remaining internal uses of dns.rdata.choose_relativity(), which prevents rdata from being immutable.
Diffstat (limited to 'dns/tokenizer.py')
-rw-r--r--dns/tokenizer.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/dns/tokenizer.py b/dns/tokenizer.py
index 74674a6..479c002 100644
--- a/dns/tokenizer.py
+++ b/dns/tokenizer.py
@@ -528,7 +528,7 @@ class Tokenizer(object):
raise dns.exception.SyntaxError('expecting an identifier')
return token.value
- def get_name(self, origin=None):
+ def get_name(self, origin=None, relativize=False, relativize_to=None):
"""Read the next token and interpret it as a DNS name.
Raises dns.exception.SyntaxError if not a name.
@@ -539,7 +539,8 @@ class Tokenizer(object):
token = self.get()
if not token.is_identifier():
raise dns.exception.SyntaxError('expecting an identifier')
- return dns.name.from_text(token.value, origin)
+ name = dns.name.from_text(token.value, origin)
+ return name.choose_relativity(relativize_to or origin, relativize)
def get_eol(self):
"""Read the next token and raise an exception if it isn't EOL or