diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2014-06-30 18:38:23 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2014-06-30 18:38:23 +0100 |
commit | ed58d3ac7e69c46668211e883d961cb5a262dc86 (patch) | |
tree | 77c75f48294111d2cad5097fd8c0aea850882551 | |
parent | e1661f4722d54f9ba7eda006055492201cdc196c (diff) | |
download | sos-ed58d3ac7e69c46668211e883d961cb5a262dc86.tar.gz |
[plugin] fix unicode vs. byte array handling in string IO
Causes a nosetests failure on python3:
======================================================================
ERROR: test_glob_file_over_limit (plugin_tests.AddCopySpecTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/breeves/src/git/sos/tests/plugin_tests.py", line 269, in test_glob_file_over_limit
self.mp.add_copy_spec_limit("/tmp/tmp*", 1)
File "/home/breeves/src/git/sos/sos/plugins/__init__.py", line 414, in add_copy_spec_limit
self.add_string_as_file(tail(_file, sizelimit), strfile)
File "/home/breeves/src/git/sos/sos/plugins/__init__.py", line 520, in add_string_as_file
content = "..." + content.splitlines()[0]
TypeError: Can't convert 'bytes' object to str implicitly
======================================================================
ERROR: test_single_file_over_limit (plugin_tests.AddCopySpecTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/breeves/src/git/sos/tests/plugin_tests.py", line 253, in test_single_file_over_limit
self.mp.add_copy_spec_limit(fn, 1)
File "/home/breeves/src/git/sos/sos/plugins/__init__.py", line 414, in add_copy_spec_limit
self.add_string_as_file(tail(_file, sizelimit), strfile)
File "/home/breeves/src/git/sos/sos/plugins/__init__.py", line 520, in add_string_as_file
content = "..." + content.splitlines()[0]
TypeError: Can't convert 'bytes' object to str implicitly
----------------------------------------------------------------------
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index f78f1e21..b7f28015 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -517,7 +517,7 @@ class Plugin(object): def add_string_as_file(self, content, filename): """Add a string to the archive as a file named `filename`""" self.copy_strings.append((content, filename)) - content = "..." + content.splitlines()[0] + content = "..." + (content.splitlines()[0]).decode('utf8') self.log_debug("added string '%s' as '%s'" % (content,filename)) def get_cmd_output_now(self, exe, suggest_filename=None, @@ -584,8 +584,8 @@ class Plugin(object): def collect_strings(self): for string, file_name in self.copy_strings: - self.log_info("collecting string '%s' as '%s'" - % ("..." + string.splitlines()[0], file_name)) + content = "..." + (string.splitlines()[0]).decode('utf8') + self.log_info("collecting string '%s' as '%s'" % (content, file_name)) try: self.archive.add_string(string, os.path.join('sos_strings', self.name(), file_name)) |