On Wed, Sep 15, 2021 at 11:40:31AM -0400, John Snow wrote: > A few new annoyances. Of note is the new warning for an unspecified > encoding when opening a text file, which actually does indicate a > potentially real problem; see > https://www.python.org/dev/peps/pep-0597/#motivation > > Use LC_CTYPE to determine an encoding to use for interpreting QEMU's > terminal output. Note that Python states: "language code and encoding > may be None if their values cannot be determined" -- use a platform > default as a backup. > > Signed-off-by: John Snow <js...@redhat.com> > --- > python/qemu/machine/machine.py | 9 ++++++++- > python/setup.cfg | 1 + > 2 files changed, 9 insertions(+), 1 deletion(-) > > diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py > index a7081b1845..51b6e79a13 100644 > --- a/python/qemu/machine/machine.py > +++ b/python/qemu/machine/machine.py > @@ -19,6 +19,7 @@ > > import errno > from itertools import chain > +import locale > import logging > import os > import shutil > @@ -290,8 +291,14 @@ def get_pid(self) -> Optional[int]: > return self._subp.pid > > def _load_io_log(self) -> None: > + # Assume that the output encoding of QEMU's terminal output > + # is defined by our locale. If indeterminate, use a platform default. > + _, encoding = locale.getlocale() > + if encoding is None: > + encoding = locale.getpreferredencoding(do_setlocale=False)
Do we really need this getpreferredencoding ? IIUC, this is a sign that the application is buggy by not calling locale.setlocale(locale.LC_ALL, '') during its main() method, which I think we can just delegate to the code in question to fix. Missing setlocale will affect everything they run, so doing workarounds in only 1 place is not worth it IMHO > if self._qemu_log_path is not None: > - with open(self._qemu_log_path, "r") as iolog: > + with open(self._qemu_log_path, "r", > + encoding=encoding) as iolog: > self._iolog = iolog.read() Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|