From 0e9e9f2e9743b32ad0721b93a7497b640b5bf177 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Tue, 31 Jul 2018 01:54:15 +0200 Subject: Fix #1210 for Python 2 (it was never broken for Python 3) The new code from commit 08b08d70 returned a 'unicode' object instead of 'str' but here we were explicitly expecting 'str'. I wanted to use `isinstance(source, basestring)` (or `(str, unicode)` instead of `basestring`)) there but it won't work under Python 3. For now I'm re-encoding every Python 2 unicode string to a UTF-8 encoded 'str' object even though 'unicode' should work just as well, because it would be cumbersome under Python 3 otherwise. --- ranger/core/actions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ranger/core/actions.py b/ranger/core/actions.py index ae8e33d4..f8364250 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -1088,7 +1088,11 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m data[(-1, -1)] = None data['foundpreview'] = False elif rcode == 2: - data[(-1, -1)] = self.read_text_file(path, 1024 * 32) + text = self.read_text_file(path, 1024 * 32) + if not isinstance(text, str): + # Convert 'unicode' to 'str' in Python 2 + text = text.encode('utf-8') + data[(-1, -1)] = text else: data[(-1, -1)] = None -- cgit 1.4.1-2-gfad0