aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2014-04-16 17:28:59 +0100
committerBryn M. Reeves <bmr@redhat.com>2014-04-16 17:28:59 +0100
commitfc908156bb888effc3e973f09ede606b7ab1476c (patch)
treef66bf4c04496c1a1e2a2b5ac31540c74afdbf292
parentf6bcd6abd9d3dc30a951091fe54ed20057a109dd (diff)
downloadsos-fc908156bb888effc3e973f09ede606b7ab1476c.tar.gz
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 <bmr@redhat.com>
-rw-r--r--sos/archive.py5
1 files 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)