Skip to content

Commit

Permalink
Apply the unicode-sandwich principle.
Browse files Browse the repository at this point in the history
When we receive byte strings, convert them to unicode as early in the
pipeline as possible.  This fixes my python-3 test suite locally.
  • Loading branch information
ralphbean committed Jan 19, 2015
1 parent 55090cd commit 05e4e83
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions taskw/warrior.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,15 @@ def _execute(self, *args):
if proc.returncode != 0:
raise TaskwarriorError(command, stderr, stdout, proc.returncode)

# 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'))

return stdout, stderr

def _get_json(self, *args):
encoded = self._execute(*args)[0]
decoded = encoded.decode(self.config.get('encoding', 'utf-8'))
return json.loads(decoded)
return json.loads(self._execute(*args)[0])

def _get_task_objects(self, *args):
json = self._get_json(*args)
Expand Down

0 comments on commit 05e4e83

Please sign in to comment.