[PATCH 1 of 2 v2] kallithea_config: properly handle Unicode characters in .ini template

Mads Kiilerich mads at kiilerich.com
Thu Aug 6 20:44:00 UTC 2015


On 08/06/2015 02:53 PM, Thomas De Schampheleire wrote:
> # HG changeset patch
> # User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
> # 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')

It seems a bit unfortunate to hardcode utf-8 here. The user could be 
using another encoding for their .ini file .

Would an update to a later version of the ini file reader "solve" this 
problem? It seems wrong to work around it here.

I guess it is less relevant without the error mail subject prefix? 
Perhaps ask upstream here too and wait for a better fix?

/Mads



More information about the kallithea-general mailing list