From f513760769e5e0c7ba08f171e4d5399000b8ae51 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 25 Jun 2012 14:26:43 +0200 Subject: Use Popen.communicate() instead of stdin, stdout --- apt/auth.py | 22 ++++++++++++---------- debian/changelog | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apt/auth.py b/apt/auth.py index 1a81d3b0..5d4b1cd6 100644 --- a/apt/auth.py +++ b/apt/auth.py @@ -70,17 +70,19 @@ def _call_apt_key_script(*args, **kwargs): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - try: - proc.stdin.write(kwargs["stdin"]) - except KeyError: - pass - finally: - proc.stdin.close() - return_code = proc.wait() - output = proc.stdout.read() - if return_code: + + content = kwargs.get("stdin", None) + if isinstance(content, unicode): + content = content.encode("utf-8") + + output, stderr = proc.communicate(content) + + assert stderr == None + + if proc.returncode: raise SystemError("The apt-key script failed with return code %s:\n" - "%s\n%s" % (return_code, " ".join(cmd), output)) + "%s\n%s" % (proc.returncode, " ".join(cmd), + output)) return output.strip() finally: if conf is not None: diff --git a/debian/changelog b/debian/changelog index e6d6d648..627ef655 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,7 @@ python-apt (0.8.6) UNRELEASED; urgency=low [ Julian Andres Klode ] * apt/auth.py: - Use tempfile.NamedTemporaryFile to create temporary file + - Use Popen.communicate() instead of stdin, stdout -- Michael Vogt Mon, 25 Jun 2012 13:41:02 +0200 -- cgit v1.2.3