[elbe-devel] [PATCH 1/1] Better Unicode errors handling in licence generation
Bastian Germann
bage at linutronix.de
Tue Jul 23 10:21:36 CEST 2019
> From: Olivier Dion <dion at linutronix.de>
>
> See <https://github.com/Linutronix/elbe/issues/133>.
>
> According to <https://docs.python.org/2.7/library/functions.html#unicode>,
> the only possible exception that can be throw is a 'LookupError' if
thrown
> the encoding is not known or a ValueError when the errors handling is
> set to "strict".
>
> Setting the errors handling to "replace" will prevent the latter to
error handling
> ever happen.
>
> This will also ensure that _all_ generated licence file are in full
files
> utf-8, no matter what happen.
happens
>
> See <https://www.debian.org/doc/debian-policy/ch-docs.html#s-copyrightfile>.
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
With these applied
Reviewed-by: Bastian Germann <bage at linutronix.de>
> ---
> elbepack/efilesystem.py | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/elbepack/efilesystem.py b/elbepack/efilesystem.py
> index 8d766e3c..277ba112 100644
> --- a/elbepack/efilesystem.py
> +++ b/elbepack/efilesystem.py
> @@ -150,10 +150,7 @@ class ElbeFilesystem(Filesystem):
> lic_text = "Error while processing license file %s: '%s'" % (
> os.path.join(d, "copyright"), e.strerror)
>
> - try:
> - lic_text = unicode(lic_text, encoding='utf-8')
> - except BaseException:
> - lic_text = unicode(lic_text, encoding='iso-8859-1')
> + lic_text = unicode(lic_text, encoding='utf-8', errors='replace')
>
> if f is not None:
> f.write(unicode(os.path.basename(d)))
>
More information about the elbe-devel
mailing list