From 99eb38c6b9688da453e98d07c356cb4698ecc3e8 Mon Sep 17 00:00:00 2001
From: Sebastien Luttringer <sebastien.luttringer@smartjog.com>
Date: Tue, 18 Oct 2011 13:00:49 +0200
Subject: [PATCH] Fix issue with utf8 encoding in author

=> Image debian-generic v4 loaded
Error: 'ascii' codec can't encode character u'\xe9' in position 27: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/bin/is", line 482, in <module>
    error(e)
  File "/usr/bin/is", line 480, in <module>
    args.func(p_main, args)
  File "/usr/bin/is", line 242, in c_list
    img, repo = select_image(o, repoman, args.best)
  File "/usr/bin/is", line 64, in select_image
    return repoman.get(image, version, best)
  File "/usr/lib/python2.6/dist-packages/installsystems/repository.py", line 616, in get
    return repo.get(name, version), repo
  File "/usr/lib/python2.6/dist-packages/installsystems/repository.py", line 399, in get
    pkg = PackageImage(path, fileobj=memfile, md5name=True)
  File "/usr/lib/python2.6/dist-packages/installsystems/image.py", line 458, in __init__
    arrow("Author: %s" % self.author, 1)
  File "/usr/lib/python2.6/dist-packages/installsystems/printer.py", line 107, in arrow
    out(" #light##yellow#=>#reset# %s" % message)
  File "/usr/lib/python2.6/dist-packages/installsystems/printer.py", line 55, in out
    fd.write("%s%s" % (message, endl))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 27: ordinal not in range(128)
---
 installsystems/printer.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/installsystems/printer.py b/installsystems/printer.py
index d5926a1..4aec988 100644
--- a/installsystems/printer.py
+++ b/installsystems/printer.py
@@ -51,6 +51,10 @@ def out(message="", fd=sys.stdout, endl=os.linesep, flush=True):
             message = message.replace("#%s#" % c, color[c])
         else:
             message = message.replace("#%s#" % c, "")
+    # convert unicode into str before write
+    # this can cause issue on python 2.6
+    if type(message) == unicode:
+        message = message.encode("utf8")
     # printing
     fd.write("%s%s" % (message, endl))
     if flush:
-- 
GitLab