Skip to content

Commit aec4014

Browse files
committed
#32 Support for special characters / unicode.
1 parent fdeb3de commit aec4014

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

tmuxp/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
:license: BSD, see LICENSE for details
99
1010
"""
11+
from __future__ import absolute_import, division, print_function, \
12+
with_statement, unicode_literals
1113

1214
import sys
1315
import os

tmuxp/_compat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
from string import ascii_lowercase
3131
import urllib.parse as urllib
3232
import urllib.parse as urlparse
33+
34+
console_encoding = sys.__stdout__.encoding
35+
36+
def console_to_str(s):
37+
""" From pypa/pip project, pip.backwardwardcompat. License MIT. """
38+
try:
39+
return s.decode(console_encoding)
40+
except UnicodeDecodeError:
41+
return s.decode('utf_8')
3342
else:
3443
text_type = unicode
3544
string_types = (str, unicode)
@@ -55,5 +64,8 @@
5564
from string import lower as ascii_lowercase
5665
import urlparse
5766

67+
def console_to_str(s):
68+
return s.decode('utf_8')
69+
5870

5971
number_types = integer_types + (float,)

tmuxp/exc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
99
"""
1010

11+
from __future__ import absolute_import, division, print_function, \
12+
with_statement, unicode_literals
13+
1114

1215
class TmuxpException(Exception):
1316

tmuxp/formats.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
1212
"""
1313

14+
from __future__ import absolute_import, division, print_function, \
15+
with_statement, unicode_literals
16+
17+
1418
SESSION_FORMATS = [
1519
'session_name',
1620
'session_windows',

tmuxp/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
:license: BSD, see LICENSE for details
1111
1212
"""
13-
from __future__ import absolute_import, division, print_function, with_statement
13+
from __future__ import absolute_import, division, print_function, \
14+
with_statement, unicode_literals
1415

1516
import pipes
1617
import logging
@@ -61,7 +62,6 @@ def by(val, *args):
6162
return list(filter(by, self.server._sessions))[0]
6263
except IndexError as e:
6364
logger.error(e)
64-
logger.error(self.server._sessions)
6565

6666
def tmux(self, *args, **kwargs):
6767
"""Return :meth:`Server.tmux`.

tmuxp/util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
from . import exc
2626

27+
from ._compat import console_to_str
28+
2729
logger = logging.getLogger(__name__)
2830

2931
PY2 = sys.version_info[0] == 2
@@ -77,10 +79,13 @@ def __init__(self, *args, **kwargs):
7779
e
7880
)
7981
)
80-
self.stdout = stdout.decode().split('\n')
82+
83+
self.stdout = console_to_str(stdout)
84+
self.stdout = self.stdout.split('\n')
8185
self.stdout = list(filter(None, self.stdout)) # filter empty values
8286

83-
self.stderr = stderr.decode().split('\n')
87+
self.stderr = console_to_str(stderr)
88+
self.stderr = self.stderr.split('\n')
8489
self.stderr = list(filter(None, self.stderr)) # filter empty values
8590

8691
if 'has-session' in cmd and len(self.stderr):

0 commit comments

Comments
 (0)