Fix bytes -> str handling in linux.dig action
# limitations under the License.
import errno
+import locale
import subprocess
import random
import re
@@ -42,12 +43,15 @@ class DigAction(Action):
cmd_args.append(hostname)
+ # This function might call getpreferred encoding unless we pass
+ # do_setlocale=False.
+ encoding = locale.getpreferredencoding(do_setlocale=False)
try:
- result_list = filter(None, subprocess.Popen(cmd_args,
+ result_list = list(filter(None, subprocess.Popen(cmd_args,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
- .communicate()[0]
- .split('\n'))
+ .communicate()[0].decode(encoding)
+ .split('\n')))
# NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat
# for Python3:
