diff options
| author | Brian Wellington <bwelling@xbill.org> | 2020-06-30 16:35:20 -0700 |
|---|---|---|
| committer | Brian Wellington <bwelling@xbill.org> | 2020-06-30 16:35:20 -0700 |
| commit | 7c0accbb5412d4065446543077ab625daf9749af (patch) | |
| tree | 949b8a78e803b8501cf3e0e25b5ca49bffdb9690 /dns/tokenizer.py | |
| parent | 8cfbca6a255a64f127c58034bbd32189a9cb5af4 (diff) | |
| download | dnspython-7c0accbb5412d4065446543077ab625daf9749af.tar.gz | |
Add Tokenizer.concatenate_remaining_identifiers()
Replace identical code duplicated in a number of rdatatype
implementations that concatenated all of the remaining tokens in order
to decode them.
Diffstat (limited to 'dns/tokenizer.py')
| -rw-r--r-- | dns/tokenizer.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/dns/tokenizer.py b/dns/tokenizer.py index cb5ebd3..3e5d2ba 100644 --- a/dns/tokenizer.py +++ b/dns/tokenizer.py @@ -559,6 +559,25 @@ class Tokenizer: raise dns.exception.SyntaxError('expecting an identifier') return token.value + def concatenate_remaining_identifiers(self): + """Read the remaining tokens on the line, which should be identifiers. + + Raises dns.exception.SyntaxError if a token is seen that is not an + identifier. + + Returns a string containing a concatenation of the remaining + identifiers. + """ + s = "" + while True: + token = self.get().unescape() + if token.is_eol_or_eof(): + break + if not token.is_identifier(): + raise dns.exception.SyntaxError + s += token.value + return s + def as_name(self, token, origin=None, relativize=False, relativize_to=None): """Try to interpret the token as a DNS name. |
