Skip to content

Commit

Permalink
Use kitchen in the most dire of circumstances.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Feb 1, 2016
1 parent de5fa87 commit 11cdab5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
six
python-dateutil
pytz
kitchen
16 changes: 14 additions & 2 deletions taskw/warrior.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import subprocess
import json

import kitchen.text.converters

import six
from six import with_metaclass
from six.moves import filter
Expand Down Expand Up @@ -472,8 +474,18 @@ def _execute(self, *args):

# We should get bytes from the outside world. Turn those into unicode
# as soon as we can.
stdout = stdout.decode(self.config.get('encoding', 'utf-8'))
stderr = stderr.decode(self.config.get('encoding', 'utf-8'))
# Everything going into and coming out of taskwarrior *should* be
# utf-8, but there are weird edge cases where something totally unusual
# made it in.. so we need to be able to handle (or at least try to
# handle) whatever. Kitchen tries its best.
try:
stdout = stdout.decode(self.config.get('encoding', 'utf-8'))
except UnicodeDecodeError as e:
stdout = kitchen.text.converters.to_unicode(stdout)
try:
stderr = stderr.decode(self.config.get('encoding', 'utf-8'))
except UnicodeDecodeError as e:
stderr = kitchen.text.converters.to_unicode(stderr)

return stdout, stderr

Expand Down

0 comments on commit 11cdab5

Please sign in to comment.