Commit 86c19606 authored by Jacek Sowiński's avatar Jacek Sowiński

Fix unicode values in aliases config in python2

Apparently shlex and ConfigParser.read() don't work well with Unicode
input in python2.
parent bd24c1df
...@@ -34,6 +34,7 @@ setup( ...@@ -34,6 +34,7 @@ setup(
], ],
extras_require = { extras_require = {
':sys_platform=="win32"': ['colorama>=0.2.5'], ':sys_platform=="win32"': ['colorama>=0.2.5'],
':python_version=="2.7"': ['ushlex'],
'ical': ['icalendar'], 'ical': ['icalendar'],
'prompt-toolkit': ['prompt-toolkit >= 0.53'], 'prompt-toolkit': ['prompt-toolkit >= 0.53'],
'edit-cmd-tests': ['mock'], 'edit-cmd-tests': ['mock'],
......
...@@ -54,6 +54,14 @@ class GetSubcommandTest(TopydoTest): ...@@ -54,6 +54,14 @@ class GetSubcommandTest(TopydoTest):
self.assertTrue(issubclass(real_cmd, ListCommand)) self.assertTrue(issubclass(real_cmd, ListCommand))
self.assertEqual(final_args, ["-F", "|I| x c d {(}p{)} s k", "-n", "25"]) self.assertEqual(final_args, ["-F", "|I| x c d {(}p{)} s k", "-n", "25"])
def test_alias03(self):
config("test/data/aliases.conf")
args = ["smile"]
real_cmd, final_args = get_subcommand(args)
self.assertTrue(issubclass(real_cmd, ListCommand))
self.assertEqual(final_args, [u("\u263b")])
def test_default_cmd01(self): def test_default_cmd01(self):
args = ["bar"] args = ["bar"]
real_cmd, final_args = get_subcommand(args) real_cmd, final_args = get_subcommand(args)
......
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
foo = rm -f test foo = rm -f test
baz = FooBar baz = FooBar
format = ls -F "|I| x c d {(}p{)} s k" -n 25 format = ls -F "|I| x c d {(}p{)} s k" -n 25
smile = ls
...@@ -17,9 +17,13 @@ ...@@ -17,9 +17,13 @@
import os import os
import shlex import shlex
from six import iteritems from six import iteritems, PY2
from six.moves import configparser from six.moves import configparser
if PY2:
import ushlex as shlex
import codecs
class ConfigError(Exception): class ConfigError(Exception):
def __init__(self, p_text): def __init__(self, p_text):
self.text = p_text self.text = p_text
...@@ -132,6 +136,14 @@ class _Config: ...@@ -132,6 +136,14 @@ class _Config:
if p_path is not None: if p_path is not None:
files = [p_path] files = [p_path]
if PY2:
for path in files:
try:
with codecs.open(path, 'r', encoding='utf-8') as f:
self.cp.readfp(f)
except IOError:
pass
else:
self.cp.read(files) self.cp.read(files)
self._supplement_sections() self._supplement_sections()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment