Commit 6e234f58 authored by Petr Špaček's avatar Petr Špaček

Merge branch 'nits' into 'master'

Small tweaks

See merge request !106
parents 9c32bfcc f378d41d
Pipeline #35060 passed with stage
in 1 minute and 4 seconds
......@@ -24,7 +24,8 @@ let domain = [ label "domain" . store domain_re ]
let ttl = [label "ttl" . store /[0-9]+/]
let class = [label "class" . store class_re ]
let type = [label "type" . store ((/[^0-9#;\n \t][^\t\n\/#; ]*/) - class_re) ]
let data_re = /([^ \t\n#;][^\n#;]*[^ \t\n#;])|[^ \t\n#;]/ (*Can not start nor end with whitespace but can have whitespace in the middle. Disjunction is there so we match strings of length one.*)
(* RFC 3597 section 5 rdata syntax is "\# 1 ab"*)
let data_re = /((\\\#[ \t])?[^ \t\n#;][^\n#;]*[^ \t\n#;])|[^ \t\n#;]/ (*Can not start nor end with whitespace but can have whitespace in the middle. Disjunction is there so we match strings of length one.*)
let data = [label "data" . store data_re ]
let ip_re = /[0-9a-f.:]+/
......
......@@ -3,6 +3,11 @@
import dns.rcode
import dns.edns
from typing import ( # noqa
Any, Sequence, Union)
MismatchValue = Union[str, Sequence[Any]]
class DataMismatch(Exception):
def __init__(self, exp_val, got_val):
......@@ -10,8 +15,17 @@ class DataMismatch(Exception):
self.exp_val = exp_val
self.got_val = got_val
def __str__(self):
return 'expected "{0.exp_val}" got "{0.got_val}"'.format(self)
@staticmethod
def format_value(value: MismatchValue) -> str:
if isinstance(value, list):
return ' '.join([str(val) for val in value])
else:
return str(value)
def __str__(self) -> str:
return 'expected "{}" got "{}"'.format(
self.format_value(self.exp_val),
self.format_value(self.got_val))
def __hash__(self):
return hash((self.exp_val, self.got_val))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment