summaryrefslogtreecommitdiff
path: root/alot/helper.py
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 /alot/helper.py
parent6c4e8c4e3919042b51c8ca95c2d219736976f2e1 (diff)
helper: py3k fixes
Diffstat (limited to 'alot/helper.py')
-rw-r--r--alot/helper.py14
1 files changed, 9 insertions, 5 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