Skip to content

Commit 0b77906

Browse files
committed
Make more extensive testing and more generic fix
1 parent f1a3752 commit 0b77906

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

libtmux/_compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ def reraise(tp, value, tb=None):
9090

9191

9292
number_types = integer_types + (float,)
93+
94+
def str_from_console(s):
95+
try:
96+
return text_type(s)
97+
except UnicodeDecodeError:
98+
return text_type(s, encoding='utf_8')

libtmux/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from distutils.version import LooseVersion
1515

1616
from . import exc
17-
from ._compat import console_to_str, text_type
17+
from ._compat import console_to_str, str_from_console
1818

1919
logger = logging.getLogger(__name__)
2020

@@ -195,7 +195,7 @@ def __init__(self, *args, **kwargs):
195195

196196
cmd = [tmux_bin]
197197
cmd += args # add the command arguments to cmd
198-
cmd = [text_type(c, encoding='utf_8') for c in cmd]
198+
cmd = [str_from_console(c) for c in cmd]
199199

200200
self.cmd = cmd
201201

tests/test_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_tmux_cmd_raises_on_not_found():
161161

162162

163163
def test_tmux_cmd_unicode():
164-
tmux_cmd('has-session', 'юникод')
164+
tmux_cmd('new-window', '-t', 3, '-n', 'юникод', '-F', u'Ελληνικά')
165165

166166

167167
@pytest.mark.parametrize("session_name,raises,exc_msg_regex", [

0 commit comments

Comments
 (0)