[elbe-devel] [PATCH 1/1] Better Unicode errors handling in licence generation

dion at linutronix.de dion at linutronix.de
Tue Jul 23 10:15:22 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
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
ever happen.

This will also ensure that _all_ generated licence file are in full
utf-8, no matter what happen.

See <https://www.debian.org/doc/debian-policy/ch-docs.html#s-copyrightfile>.

Signed-off-by: Olivier Dion <dion 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)))
-- 
2.11.0




More information about the elbe-devel mailing list