From fc908156bb888effc3e973f09ede606b7ab1476c Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 16 Apr 2014 17:28:59 +0100 Subject: Use uft-8 encoding for archive IO When reading and writing files within the archive class use the codecs module and set the 'utf-8' encoding. This prevents encoding exceptions if a plugin passes a unicode string to add_string() or if a plugin attempts to read unicode encoded data from an archive file via the open_file() method. Fixes Issue #275. Signed-off-by: Bryn M. Reeves --- sos/archive.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sos/archive.py b/sos/archive.py index a252ee06..f16e4074 100644 --- a/sos/archive.py +++ b/sos/archive.py @@ -23,6 +23,7 @@ import shutil import logging import shlex import re +import codecs # required for compression callout (FIXME: move to policy?) from subprocess import Popen, PIPE @@ -158,7 +159,7 @@ class FileCacheArchive(Archive): src = dest dest = self.dest_path(dest) self._check_path(dest) - f = open(dest, 'w') + f = codecs.open(dest, 'w', encoding='utf-8') f.write(content) if os.path.exists(src): try: @@ -195,7 +196,7 @@ class FileCacheArchive(Archive): def open_file(self, path): path = self.dest_path(path) - return open(path, "r") + return codecs.open(path, "r", encoding='utf-8') def cleanup(self): shutil.rmtree(self._archive_root) -- cgit