From 1ee161e162ff9c50e18124eac47a434ff327f500 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Fri, 7 Feb 2014 04:31:25 +0100 Subject: [PATCH] cms: Use universal_newlines=True in subprocess.Popen() The Python documentation states that "the type of [the first argument of subprocess.communicate()] must be bytes or, if universal_newlines was True, a string"[1]. Currently, in Python 3, a text string is given to subprocess.communicate(), even though the process was created with universal_newlines=False (the default value). Rather than converting strings to bytes (and the other way around) everywhere in the code, just create the process with universal_newlines=True. The side effect is that '\n', '\r\n' and '\r' will be recognized as ending lines[2], which should not be an issue. [1] http://docs.python.org/3/library/subprocess.html?highlight=popen#subprocess.Popen.communicate [2] http://docs.python.org/3/glossary.html#term-universal-newlines Change-Id: I668b187ba8ed00ad6d55ec487af623b79b21589d --- keystoneclient/common/cms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/keystoneclient/common/cms.py b/keystoneclient/common/cms.py index eb64e1f6c..6ff060ba0 100644 --- a/keystoneclient/common/cms.py +++ b/keystoneclient/common/cms.py @@ -114,7 +114,8 @@ def cms_verify(formatted, signing_cert_file_name, ca_file_name): "-nocerts", "-noattr"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.PIPE, + universal_newlines=True) output, err, retcode = _process_communicate_handle_oserror( process, formatted, (signing_cert_file_name, ca_file_name)) @@ -225,7 +226,8 @@ def cms_sign_text(text, signing_cert_file_name, signing_key_file_name): "-nocerts", "-noattr"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.PIPE, + universal_newlines=True) output, err, retcode = _process_communicate_handle_oserror( process, text, (signing_cert_file_name, signing_key_file_name))