[elbe-devel] [PATCH] Prevent UnicodeEncodeError on initvm creation
Torben Hohn
torben.hohn at linutronix.de
Fri Feb 7 12:05:36 CET 2020
On Sat, Feb 01, 2020 at 10:22:22AM +0100, bage at linutronix.de wrote:
> From: Bastian Germann <bage at linutronix.de>
>
> 4643a4e8bf1("Python3: harmonize binary/unicode strings") introduced a bytes to
> string conversion in elbepack.log that makes initvm creation throw a
> UnicodeEncodeError (that is ignored) with Python 2. Remove that conversion.
>
> I successfully built some examples with Python 3 and it seems the former change
> is unnecessary at this point.
Sorry, i dont understand, what the problem is here.
rest is bytes() (that is str in python2)
but its the returnvalue of os.read which is binary data.
this needs to be decoded, to become unicode.
can you show the exact exception. because i dont see what shall fail.
why are we using TextIOWrapper() and not plain .decode() ?
TextIOWrapper is only necessary, if we can not be sure, that the bytes
we have read are chopped at utf-8 char boundaries.
but i only see that read() is called. that reads until eof...
>
> Signed-off-by: Bastian Germann <bage at linutronix.de>
> ---
> elbepack/log.py | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/elbepack/log.py b/elbepack/log.py
> index bffc6c1d4..f17df9e71 100644
> --- a/elbepack/log.py
> +++ b/elbepack/log.py
> @@ -11,8 +11,6 @@ import select
> import threading
> from contextlib import contextmanager
>
> -from io import TextIOWrapper, BytesIO
> -
> root = logging.getLogger()
> root.setLevel(logging.DEBUG)
> local = threading.local()
> @@ -257,8 +255,6 @@ class AsyncLogging(object):
> if not rest:
> break
>
> - rest = TextIOWrapper(BytesIO(rest), encoding='utf-8', errors='replace').read()
> -
> if self.lines:
> self.lines[-1] += rest
> self.block.info("\n".join(self.lines))
> --
> 2.20.1
>
--
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Hinweise zum Datenschutz finden Sie hier (Informations on data privacy
can be found here): https://linutronix.de/kontakt/Datenschutz.php
Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen |
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
More information about the elbe-devel
mailing list