From 4183a86e545defabd0e2178060538e0c2c822fa9 Mon Sep 17 00:00:00 2001 From: mingmingrr Date: Sun, 28 Jan 2024 00:00:07 -0500 Subject: [PATCH] exts: Fix Python 2.6 compatibility issues --- ranger/ext/img_display.py | 11 ++++++----- ranger/ext/popen_forked.py | 11 +++++------ ranger/ext/rifle.py | 11 +++++------ ranger/ext/which.py | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index da88acdd3d..5d8c8265cb 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -456,11 +456,13 @@ def __init__(self): def _clear_cache(self, path): if os.path.exists(path): - self.cache = { - ce: cd + # pylint: disable=consider-using-dict-comprehension + # COMPAT Dictionary comprehensions didn't exist before 2.7 + self.cache = dict([ + (ce, cd) for ce, cd in self.cache.items() if ce.inode != os.stat(path).st_ino - } + ]) def _sixel_cache(self, path, width, height): stat = os.stat(path) @@ -478,8 +480,7 @@ def _sixel_cache(self, path, width, height): environ.setdefault("MAGICK_OCL_DEVICE", "true") try: check_call( - [ - *MAGICK_CONVERT_CMD_BASE, + list(MAGICK_CONVERT_CMD_BASE) + [ path + "[0]", "-geometry", "{0}x{1}>".format(fit_width, fit_height), diff --git a/ranger/ext/popen_forked.py b/ranger/ext/popen_forked.py index 40a5b83325..03d7436f82 100644 --- a/ranger/ext/popen_forked.py +++ b/ranger/ext/popen_forked.py @@ -19,12 +19,11 @@ def Popen_forked(*args, **kwargs): # pylint: disable=invalid-name return False if pid == 0: os.setsid() - with open(os.devnull, 'r', encoding="utf-8") as null_r, open( - os.devnull, 'w', encoding="utf-8" - ) as null_w: - kwargs['stdin'] = null_r - kwargs['stdout'] = kwargs['stderr'] = null_w - Popen(*args, **kwargs) # pylint: disable=consider-using-with + with open(os.devnull, 'r', encoding="utf-8") as null_r: + with open(os.devnull, 'w', encoding="utf-8") as null_w: + kwargs['stdin'] = null_r + kwargs['stdout'] = kwargs['stderr'] = null_w + Popen(*args, **kwargs) # pylint: disable=consider-using-with os._exit(0) # pylint: disable=protected-access else: os.wait() diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index 83f35f006e..ef2a5e9d58 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -145,12 +145,11 @@ def Popen_forked(*args, **kwargs): # pylint: disable=invalid-name if pid == 0: os.setsid() # pylint: disable=unspecified-encoding - with open(os.devnull, "r") as null_r, open( - os.devnull, "w" - ) as null_w: - kwargs["stdin"] = null_r - kwargs["stdout"] = kwargs["stderr"] = null_w - Popen(*args, **kwargs) # pylint: disable=consider-using-with + with open(os.devnull, "r") as null_r: + with open(os.devnull, "w") as null_w: + kwargs["stdin"] = null_r + kwargs["stdout"] = kwargs["stderr"] = null_w + Popen(*args, **kwargs) # pylint: disable=consider-using-with os._exit(0) # pylint: disable=protected-access return True diff --git a/ranger/ext/which.py b/ranger/ext/which.py index f55afe7983..4da0d63491 100644 --- a/ranger/ext/which.py +++ b/ranger/ext/which.py @@ -4,7 +4,7 @@ from __future__ import (absolute_import, division, print_function) import shutil -from subprocess import check_output, CalledProcessError +from ranger.ext.spawn import check_output, CalledProcessError from ranger import PY3