From dd58f3dfe9ff01b8b9f13e52a8717d3ae571fd1b Mon Sep 17 00:00:00 2001 From: Oleg Girko Date: Thu, 5 Nov 2015 02:54:34 +0000 Subject: [PATCH] Open metadata in binary mode for Python 3 compatibility. Python 3 handles character data read from a file differently than Python 2 does. Python 3 opens files in text mode by default, causing file reads to return string data decoded from file using encoding specified as argument of open() builtin function. If encoding is not specified, open() uses some default encoding that can even be ASCII. Hence, using open() in text mode without specifying encoding is dangerous in Python 3 and can lead to unexpected results. However, it's safe to open metadata in binary mode, it gets encoded to UTF-8 later anyway. Signed-off-by: Oleg Girko --- src/saml2/mdstore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/saml2/mdstore.py b/src/saml2/mdstore.py index ad70a68..5251f0c 100644 --- a/src/saml2/mdstore.py +++ b/src/saml2/mdstore.py @@ -589,7 +589,7 @@ class MetaDataFile(InMemoryMetaData): self.cert = cert def get_metadata_content(self): - return open(self.filename).read() + return open(self.filename, 'rb').read() def load(self): _txt = self.get_metadata_content()