Skip to content

Commit

Permalink
#32 Support for special characters / unicode.
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Dec 25, 2013
1 parent fdeb3de commit aec4014
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tmuxp/__main__.py
Expand Up @@ -8,6 +8,8 @@
:license: BSD, see LICENSE for details
"""
from __future__ import absolute_import, division, print_function, \
with_statement, unicode_literals

import sys
import os
Expand Down
12 changes: 12 additions & 0 deletions tmuxp/_compat.py
Expand Up @@ -30,6 +30,15 @@
from string import ascii_lowercase
import urllib.parse as urllib
import urllib.parse as urlparse

console_encoding = sys.__stdout__.encoding

def console_to_str(s):
""" From pypa/pip project, pip.backwardwardcompat. License MIT. """
try:
return s.decode(console_encoding)
except UnicodeDecodeError:
return s.decode('utf_8')
else:
text_type = unicode
string_types = (str, unicode)
Expand All @@ -55,5 +64,8 @@
from string import lower as ascii_lowercase
import urlparse

def console_to_str(s):
return s.decode('utf_8')


number_types = integer_types + (float,)
3 changes: 3 additions & 0 deletions tmuxp/exc.py
Expand Up @@ -8,6 +8,9 @@
"""

from __future__ import absolute_import, division, print_function, \
with_statement, unicode_literals


class TmuxpException(Exception):

Expand Down
4 changes: 4 additions & 0 deletions tmuxp/formats.py
Expand Up @@ -11,6 +11,10 @@
"""

from __future__ import absolute_import, division, print_function, \
with_statement, unicode_literals


SESSION_FORMATS = [
'session_name',
'session_windows',
Expand Down
4 changes: 2 additions & 2 deletions tmuxp/session.py
Expand Up @@ -10,7 +10,8 @@
:license: BSD, see LICENSE for details
"""
from __future__ import absolute_import, division, print_function, with_statement
from __future__ import absolute_import, division, print_function, \
with_statement, unicode_literals

import pipes
import logging
Expand Down Expand Up @@ -61,7 +62,6 @@ def by(val, *args):
return list(filter(by, self.server._sessions))[0]
except IndexError as e:
logger.error(e)
logger.error(self.server._sessions)

def tmux(self, *args, **kwargs):
"""Return :meth:`Server.tmux`.
Expand Down
9 changes: 7 additions & 2 deletions tmuxp/util.py
Expand Up @@ -24,6 +24,8 @@

from . import exc

from ._compat import console_to_str

logger = logging.getLogger(__name__)

PY2 = sys.version_info[0] == 2
Expand Down Expand Up @@ -77,10 +79,13 @@ def __init__(self, *args, **kwargs):
e
)
)
self.stdout = stdout.decode().split('\n')

self.stdout = console_to_str(stdout)
self.stdout = self.stdout.split('\n')
self.stdout = list(filter(None, self.stdout)) # filter empty values

self.stderr = stderr.decode().split('\n')
self.stderr = console_to_str(stderr)
self.stderr = self.stderr.split('\n')
self.stderr = list(filter(None, self.stderr)) # filter empty values

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

0 comments on commit aec4014

Please sign in to comment.