Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
import datetime
import functools
+import io
import logging
import sqlmodel
import typing
"""
Exports the list
"""
+ detach = False
+
+ # Convert any file handles to handle plain text
+ if not isinstance(f, io.TextIOBase):
+ f = io.TextIOWrapper(f, encoding="utf-8")
+ detach = True
+
# Write the domains as they are
if format == "domains":
for domain in self.domains:
else:
raise ValueError("Unknown output format: %s" % format)
+
+ # Detach the underlying stream. That way, the wrapper won't close
+ # the underlying file handle.
+ if detach:
+ f.detach()
name = os.path.join(args.directory, filename % list.slug)
# Create a new temporary file
- with tempfile.NamedTemporaryFile(mode="w", dir=args.directory) as f:
+ with tempfile.NamedTemporaryFile(dir=args.directory) as f:
list.export(f, format=format)
# Remove the previous file (if it exists)