summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-02-22 19:48:18 -0800
committerDylan Baker <dylan@pnwbakers.com>2018-03-01 10:34:56 -0800
commit6a8cdaf9ae7d736e55c7a389444fa874905a8bda (patch)
treed1cc6ffb9d623c20c9e07e63bb5133f36f888bf3
parent6c4e8c4e3919042b51c8ca95c2d219736976f2e1 (diff)
helper: py3k fixes
-rw-r--r--alot/helper.py14
-rw-r--r--tests/helper_test.py10
2 files changed, 14 insertions, 10 deletions
diff --git a/alot/helper.py b/alot/helper.py
index 6b67da11..daed2128 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -276,8 +276,11 @@ def call_cmd(cmdlist, stdin=None):
:param stdin: string to pipe to the process
:type stdin: str
:return: triple of stdout, stderr, return value of the shell command
- :rtype: str, str, int
+ :rtype: str, str, intd
"""
+ termenc = urwid.util.detected_encoding
+ if stdin:
+ stdin = stdin.encode(termenc)
try:
proc = subprocess.Popen(
cmdlist,
@@ -292,8 +295,8 @@ def call_cmd(cmdlist, stdin=None):
out, err = proc.communicate(stdin)
ret = proc.returncode
- out = string_decode(out, urwid.util.detected_encoding)
- err = string_decode(err, urwid.util.detected_encoding)
+ out = string_decode(out, termenc)
+ err = string_decode(err, termenc)
return out, err, ret
@@ -308,6 +311,8 @@ def call_cmd_async(cmdlist, stdin=None, env=None):
return value of the shell command
:rtype: `twisted.internet.defer.Deferred`
"""
+ termenc = urwid.util.detected_encoding
+ cmdlist = [s.encode(termenc) for s in cmdlist]
class _EverythingGetter(ProcessProtocol):
def __init__(self, deferred):
@@ -318,7 +323,6 @@ def call_cmd_async(cmdlist, stdin=None, env=None):
self.errReceived = self.errBuf.write
def processEnded(self, status):
- termenc = urwid.util.detected_encoding
out = string_decode(self.outBuf.getvalue(), termenc)
err = string_decode(self.errBuf.getvalue(), termenc)
if status.value.exitCode == 0:
@@ -339,7 +343,7 @@ def call_cmd_async(cmdlist, stdin=None, env=None):
args=cmdlist)
if stdin:
logging.debug('writing to stdin')
- proc.write(stdin)
+ proc.write(stdin.encode(termenc))
proc.closeStdin()
return d
diff --git a/tests/helper_test.py b/tests/helper_test.py
index 72729c48..1d20caa8 100644
--- a/tests/helper_test.py
+++ b/tests/helper_test.py
@@ -143,13 +143,13 @@ class TestSplitCommandstring(unittest.TestCase):
self.assertListEqual(actual, expected)
def test_bytes(self):
- base = b'echo "foo bar"'
- expected = [b'echo', b'foo bar']
+ base = 'echo "foo bar"'
+ expected = ['echo', 'foo bar']
self._test(base, expected)
def test_unicode(self):
- base = u'echo "foo €"'
- expected = [b'echo', u'foo €'.encode('utf-8')]
+ base = 'echo "foo €"'
+ expected = ['echo', 'foo €']
self._test(base, expected)
@@ -251,7 +251,7 @@ class TestPrettyDatetime(unittest.TestCase):
expected = test.strftime('%I:%M%p').lower()
else:
expected = test.strftime('%H:%M')
- expected = expected.decode('utf-8')
+ expected = expected
return expected
def test_future_seconds(self):