]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Add as_name(), allowing an already read token to be interpreted a name.
authorBob Halley <halley@dnspython.org>
Fri, 1 May 2020 22:58:14 +0000 (15:58 -0700)
committerBob Halley <halley@dnspython.org>
Fri, 1 May 2020 22:58:14 +0000 (15:58 -0700)
dns/tokenizer.py

index 66714b7fac3c0aa5ce125e717baf5b3533bc5536..4232b3f2057a3e0c99e6ba6d8cb139535e89c886 100644 (file)
@@ -528,20 +528,29 @@ class Tokenizer(object):
             raise dns.exception.SyntaxError('expecting an identifier')
         return token.value
 
-    def get_name(self, origin=None, relativize=False, relativize_to=None):
-        """Read the next token and interpret it as a DNS name.
+    def as_name(self, token, origin=None, relativize=False, relativize_to=None):
+        """Try to interpret the token as a DNS name.
 
         Raises dns.exception.SyntaxError if not a name.
 
         Returns a dns.name.Name.
         """
-
-        token = self.get()
         if not token.is_identifier():
             raise dns.exception.SyntaxError('expecting an identifier')
         name = dns.name.from_text(token.value, origin)
         return name.choose_relativity(relativize_to or origin, relativize)
 
+    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.
+
+        Returns a dns.name.Name.
+        """
+
+        token = self.get()
+        return self.as_name(token, origin, relativize, relativize_to)
+
     def get_eol(self):
         """Read the next token and raise an exception if it isn't EOL or
         EOF.