Brodie Rao  committed 2f93f1c

Fix improper usage of Popen.communicate() on Python 3

This changes test() so that it passes a string object to Popen.communicate(),
which is what we're supposed to do when using universal_newlines=True.

This fixes Python 3.3 support, but it breaks Python <= 3.2.3 support due to
a bug in subprocess. This will be fixed in Python 3.2.4.

  • Participants
  • Parent commits ee201b5

Comments (0)

Files changed (1)

         return None
     return lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)
-def encodeinput(s):
-    """Encode s so it can be used as subprocess input.
-    For Python 2, this returns the string as-is. For Python 3, it encodes it
-    based on the locale (to match open() decoding in the same manner).
-    """
-    # This is absurd. Surely there's a better way?!
-    if sys.platform == 'win32' or sys.version_info[0] == 2:
-        return s
-    return s.encode(locale.getpreferredencoding())
 def test(path, shell, indent=2):
     """Run test at path and return input, output, and diff.
             after.setdefault(pos, []).append(line)
     stdin.append('echo "\n%s %s $?"\n' % (salt, i + 1))
-    output = p.communicate(input=encodeinput(''.join(stdin)))[0]
+    output = p.communicate(input=''.join(stdin))[0]
     if p.returncode == 80:
         return (refout, None, [])