diff options
author | Wojciech Siewierski <wojciech.siewierski@onet.pl> | 2018-07-31 01:54:15 +0200 |
---|---|---|
committer | Wojciech Siewierski <wojciech.siewierski@onet.pl> | 2018-07-31 01:54:15 +0200 |
commit | 0e9e9f2e9743b32ad0721b93a7497b640b5bf177 (patch) | |
tree | 8ba5d4a99ee8ff60ec6df867415a280acace2578 | |
parent | 53e48ed044b3f69cf21a43a4c9c4450b56972165 (diff) | |
download | ranger-0e9e9f2e9743b32ad0721b93a7497b640b5bf177.tar.gz |
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 <https://github.com/ranger/ranger/blob/53e48ed044b3f69cf21a43a4c9c4450b56972165/ranger/gui/widgets/pager.py#L184> 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.
-rw-r--r-- | ranger/core/actions.py | 6 |
1 files changed, 5 insertions, 1 deletions
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 |