summaryrefslogtreecommitdiff
path: root/alot/helper.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-01-16 10:49:06 +0100
committerAnton Khirnov <anton@khirnov.net>2021-01-16 10:49:06 +0100
commit3fb4d66b584beb3fc91fc22708cd83b125b567d9 (patch)
tree93c502868e778dd8c36fb06b06f09a831622af55 /alot/helper.py
parentb1d0512f0e20b709858151818ddc508fd00dfe4a (diff)
helper: get rid of decode_string()
It just adds unnecessary type confusion. In most places where it is used, the types are always str, so it does nothing. In the few others, the encoding/decoding is better handled explicitly.
Diffstat (limited to 'alot/helper.py')
-rw-r--r--alot/helper.py32
1 files changed, 2 insertions, 30 deletions
diff --git a/alot/helper.py b/alot/helper.py
index 5800841d..27652988 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -46,31 +46,6 @@ def split_commandstring(cmdstring):
assert isinstance(cmdstring, str)
return shlex.split(cmdstring)
-
-def string_decode(string, enc='ascii'):
- """
- safely decodes string to unicode bytestring, respecting `enc` as a hint.
-
- :param string: the string to decode
- :type string: str or unicode
- :param enc: a hint what encoding is used in string ('ascii', 'utf-8', ...)
- :type enc: str
- :returns: the unicode decoded input string
- :rtype: unicode
-
- """
-
- if enc is None:
- enc = 'ascii'
- try:
- string = str(string, enc, errors='replace')
- except LookupError: # malformed enc string
- string = string.decode('ascii', errors='replace')
- except TypeError: # already str
- pass
- return string
-
-
def shorten(string, maxlen):
"""shortens string if longer than maxlen, appending ellipsis"""
if 1 < maxlen < len(string):
@@ -173,26 +148,23 @@ def call_cmd(cmdlist, stdin=None):
:rtype: str, str, int
"""
termenc = urwid.util.detected_encoding
- if isinstance(stdin, str):
- stdin = stdin.encode(termenc)
try:
logging.debug("Calling %s" % cmdlist)
proc = subprocess.Popen(
cmdlist,
+ encoding = termenc, errors = 'backslashreplace',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE if stdin is not None else None)
except OSError as e:
- out = b''
+ out = ''
err = e.strerror
ret = e.errno
else:
out, err = proc.communicate(stdin)
ret = proc.returncode
- out = string_decode(out, termenc)
- err = string_decode(err, termenc)
return out, err, ret