From efb2139eef76cf6e1bd6296bee861a001e2ceefd Mon Sep 17 00:00:00 2001 From: Klaus Ethgen Date: Sat, 23 Nov 2019 08:17:57 +0100 Subject: [PATCH] Don't fail when using non UTF-8 charset This patch fixes failure when using non UTF-8 charset. --- tasklib/backends.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tasklib/backends.py b/tasklib/backends.py index 8b0f77f..e6ccce7 100644 --- a/tasklib/backends.py +++ b/tasklib/backends.py @@ -7,6 +7,7 @@ import re import six import subprocess +import locale from .task import Task, TaskQuerySet, ReadOnlyDictView from .filters import TaskWarriorFilter @@ -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 @@ -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): @@ -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()