diff --git a/libtmux/_compat.py b/libtmux/_compat.py index 1ba32179d..0ec847f86 100644 --- a/libtmux/_compat.py +++ b/libtmux/_compat.py @@ -92,3 +92,9 @@ def reraise(tp, value, tb=None): number_types = integer_types + (float,) + +def str_from_console(s): + try: + return text_type(s) + except UnicodeDecodeError: + return text_type(s, encoding='utf_8') diff --git a/libtmux/common.py b/libtmux/common.py index f5afbc106..98bed804c 100644 --- a/libtmux/common.py +++ b/libtmux/common.py @@ -14,7 +14,7 @@ from distutils.version import LooseVersion from . import exc -from ._compat import console_to_str +from ._compat import console_to_str, str_from_console logger = logging.getLogger(__name__) @@ -196,7 +196,7 @@ def __init__(self, *args, **kwargs): cmd = [tmux_bin] cmd += args # add the command arguments to cmd - cmd = [str(c) for c in cmd] + cmd = [str_from_console(c) for c in cmd] self.cmd = cmd diff --git a/tests/test_common.py b/tests/test_common.py index 2b65ba6f4..123e549dc 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -163,6 +163,10 @@ def test_tmux_cmd_raises_on_not_found(): tmux_cmd('-V') +def test_tmux_cmd_unicode(): + tmux_cmd('new-window', '-t', 3, '-n', 'юникод', '-F', u'Ελληνικά') + + @pytest.mark.parametrize( "session_name,raises,exc_msg_regex", [