about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2021-02-28 20:46:03 +0100
committertoonn <toonn@toonn.io>2021-02-28 20:46:03 +0100
commitf1d98c1edef3a3aa656ca242df844c7a438a03eb (patch)
tree311d0ec8ebd4ecc5a61a3e319d0c0c49251b66f9 /ranger
parent20cc5e861afbe8c2afed2ce843a1ca6f0bc2f218 (diff)
parent0a801333088e74c474b77a2af21a93727f072282 (diff)
downloadranger-f1d98c1edef3a3aa656ca242df844c7a438a03eb.tar.gz
Merge branch 'SimSaladin-issue-1744'
Fixes #1744
Diffstat (limited to 'ranger')
-rw-r--r--ranger/core/filter_stack.py5
-rw-r--r--ranger/core/fm.py7
-rwxr-xr-xranger/ext/rifle.py6
3 files changed, 8 insertions, 10 deletions
diff --git a/ranger/core/filter_stack.py b/ranger/core/filter_stack.py
index 58ce1a1c..66ab95c3 100644
--- a/ranger/core/filter_stack.py
+++ b/ranger/core/filter_stack.py
@@ -6,7 +6,6 @@
 from __future__ import (absolute_import, division, print_function)
 
 import re
-import mimetypes
 # pylint: disable=invalid-name
 try:
     from itertools import izip_longest as zip_longest
@@ -59,13 +58,13 @@ class NameFilter(BaseFilter):
 
 
 @stack_filter("mime")
-class MimeFilter(BaseFilter):
+class MimeFilter(BaseFilter, FileManagerAware):
     def __init__(self, pattern):
         self.pattern = pattern
         self.regex = re.compile(pattern)
 
     def __call__(self, fobj):
-        mimetype, _ = mimetypes.guess_type(fobj.relative_path)
+        mimetype, _ = self.fm.mimetypes.guess_type(fobj.relative_path)
         if mimetype is None:
             return False
         return self.regex.search(mimetype)
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index da8b27c3..52cd83d6 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -73,9 +73,10 @@ class FM(Actions,  # pylint: disable=too-many-instance-attributes
         self.hostname = socket.gethostname()
         self.home_path = os.path.expanduser('~')
 
-        mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types'))
-        mimetypes.knownfiles.append(self.relpath('data/mime.types'))
-        self.mimetypes = mimetypes.MimeTypes()
+        if not mimetypes.inited:
+            extra_files = [self.relpath('data/mime.types'), os.path.expanduser("~/.mime.types")]
+            mimetypes.init(mimetypes.knownfiles + extra_files)
+        self.mimetypes = mimetypes
 
     def initialize(self):  # pylint: disable=too-many-statements
         """If ui/bookmarks are None, they will be initialized here."""
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index e0773324..af75ac41 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -144,7 +144,6 @@ class Rifle(object):  # pylint: disable=too-many-instance-attributes
         self.config_file = config_file
         self._app_flags = ''
         self._app_label = None
-        self._initialized_mimetypes = False
         self._mimetype = None
         self._skip = None
         self.rules = None
@@ -252,9 +251,8 @@ class Rifle(object):  # pylint: disable=too-many-instance-attributes
             return self._mimetype
 
         import mimetypes
-        for path in self._mimetype_known_files:
-            if path not in mimetypes.knownfiles:
-                mimetypes.knownfiles.append(path)
+        if not mimetypes.inited:
+            mimetypes.init(mimetypes.knownfiles + self._mimetype_known_files)
         self._mimetype, _ = mimetypes.guess_type(fname)
 
         if not self._mimetype: