# HG changeset patch
# User Thomas De Schampheleire <[email protected]>
# Date 1438854177 -7200
#      Thu Aug 06 11:42:57 2015 +0200
# Node ID 36872d5ea39382ccd6413d2d373d6f899fbd837d
# Parent  88a5fb51d83744befbdb2aaeae63d8c5e735749a
kallithea_config: properly handle Unicode characters in .ini template

The kallithea_config.py script did not allow Unicode characters in the
configuration file template template.ini.mako. Following error would be
given:
    Traceback (most recent call last):
      File 
"/home/tdescham/repo/contrib/kallithea-fixes/kallithea/bin/kallithea_config.py",
 line 141, in _run
        f.write(tmpl)
    UnicodeEncodeError: 'ascii' codec can't encode character u'\u2002' in 
position 2087: ordinal not in range(128)

diff --git a/kallithea/bin/kallithea_config.py 
b/kallithea/bin/kallithea_config.py
--- a/kallithea/bin/kallithea_config.py
+++ b/kallithea/bin/kallithea_config.py
@@ -132,13 +132,13 @@ def _run(argv):
             tmpl_file = args.template
 
         with open(tmpl_file, 'rb') as f:
-            tmpl_data = f.read()
+            tmpl_data = f.read().decode('utf-8')
             if args.raw:
                 tmpl = tmpl_data
             else:
                 tmpl = Template(tmpl_data).render(**tmpl_stored_args)
         with open(args.filename, 'wb') as f:
-            f.write(tmpl)
+            f.write(tmpl.encode('utf-8'))
         print 'Wrote new config file in %s' % (os.path.abspath(args.filename))
 
     except Exception:
_______________________________________________
kallithea-general mailing list
[email protected]
http://lists.sfconservancy.org/mailman/listinfo/kallithea-general

Reply via email to