"""
if isinstance(f, str):
- cm: contextlib.AbstractContextManager = open(f)
+ cm: contextlib.AbstractContextManager = open(f, "rt", encoding="utf-8")
else:
cm = contextlib.nullcontext(f)
with cm as f:
nameservers = []
if isinstance(f, str):
try:
- cm: contextlib.AbstractContextManager = open(f)
+ cm: contextlib.AbstractContextManager = open(f, "rt", encoding="utf-8")
except OSError:
# /etc/resolv.conf doesn't exist, can't be read, etc.
raise NoResolverConfiguration(f"cannot open {f}")
if isinstance(f, str):
if filename is None:
filename = f
- cm: contextlib.AbstractContextManager = open(f)
+ cm: contextlib.AbstractContextManager = open(f, "rt", encoding="utf-8")
else:
cm = contextlib.nullcontext(f)
with cm as f:
self.default_ttl_known,
)
)
- self.current_file = open(filename)
+ self.current_file = open(filename, "rt", encoding="utf-8")
self.tok = dns.tokenizer.Tokenizer(self.current_file, filename)
self.current_origin = new_origin
elif c == "$GENERATE":
import dns.rdtypes.svcbbase
import dns.rrset
from dns.tokenizer import Tokenizer
-
from tests.util import here
def test_svcb_spec_test_vectors(self):
text_file = here("svcb_test_vectors.text")
- text_tokenizer = Tokenizer(open(text_file), filename=text_file)
+ text_tokenizer = Tokenizer(
+ open(text_file, "rt", encoding="utf-8"), filename=text_file
+ )
generic_file = here("svcb_test_vectors.generic")
- generic_tokenizer = Tokenizer(open(generic_file), filename=generic_file)
+ generic_tokenizer = Tokenizer(
+ open(generic_file, "rt", encoding="utf-8"), filename=generic_file
+ )
while True:
while True:
def compare_files(test_name, a_name, b_name):
- with open(a_name, "r") as a:
- with open(b_name, "r") as b:
+ with open(a_name, "rt", encoding="utf-8") as a:
+ with open(b_name, "rt", encoding="utf-8") as b:
differences = list(difflib.unified_diff(a.readlines(), b.readlines()))
if len(differences) == 0:
return True
def testToFileTextual(self):
z = dns.zone.from_file(here("example"), "example")
try:
- f = open(here("example3-textual.out"), "w")
+ f = open(here("example3-textual.out"), "wt", encoding="utf-8")
z.to_file(f)
f.close()
ok = compare_files(
ok = False
try:
text_zone = z.to_text(nl="\x0a")
- f = open(here("example3.out"), "w")
+ f = open(here("example3.out"), "wt", encoding="utf-8")
f.write(text_zone)
f.close()
ok = compare_files(
def testToFileTextualWithOrigin(self):
z = dns.zone.from_file(here("example"), "example")
try:
- f = open(here("example4-textual.out"), "w")
+ f = open(here("example4-textual.out"), "wt", encoding="utf-8")
z.to_file(f, want_origin=True)
f.close()
ok = compare_files(