Skip to content

Commit

Permalink
Don't fail when using non UTF-8 charset
Browse files Browse the repository at this point in the history
This patch fixes failure when using non UTF-8 charset.
  • Loading branch information
mowgli committed Nov 23, 2019
1 parent d3e12d1 commit efb2139
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tasklib/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import six
import subprocess
import locale

from .task import Task, TaskQuerySet, ReadOnlyDictView
from .filters import TaskWarriorFilter
Expand Down Expand Up @@ -142,7 +143,7 @@ def _get_command_args(self, args, config_override=None):
for item in overrides.items():
command_args.append('rc.{0}={1}'.format(*item))
command_args.extend([
x.decode('utf-8') if isinstance(x, six.binary_type)
x.decode(locale.nl_langinfo(locale.CODESET)) if isinstance(x, six.binary_type)
else six.text_type(x) for x in args
])
return command_args
Expand All @@ -152,7 +153,7 @@ def _get_version(self):
self._get_task_command() + ['--version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = [x.decode('utf-8') for x in p.communicate()]
stdout, stderr = [x.decode(locale.nl_langinfo(locale.CODESET)) for x in p.communicate()]
return stdout.strip('\n')

def _get_modified_task_fields_as_args(self, task):
Expand Down Expand Up @@ -287,7 +288,7 @@ def execute_command(self, args, config_override=None, allow_failure=True,
env['TASKRC'] = self.taskrc_location
p = subprocess.Popen(command_args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env)
stdout, stderr = [x.decode('utf-8') for x in p.communicate()]
stdout, stderr = [x.decode(locale.nl_langinfo(locale.CODESET)) for x in p.communicate()]
if p.returncode and allow_failure:
if stderr.strip():
error_msg = stderr.strip()
Expand Down

0 comments on commit efb2139

Please sign in to comment.