about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2018-10-28 13:11:28 +0100
committertoonn <toonn@toonn.io>2018-10-28 13:12:12 +0100
commit9b1af8452642267ae982853ba331bb8fd8f22320 (patch)
tree4c1e0fc6fb6c65cd9834e2a2d18864455deaa213
parentec17480833b7c3d968e73a72394c826823dbdfe9 (diff)
downloadranger-9b1af8452642267ae982853ba331bb8fd8f22320.tar.gz
Put our guesses back in the except clause
-rw-r--r--ranger/core/actions.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index e4cc1ded..7e5765b0 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -1170,7 +1170,18 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
         try:
             import chardet
         except ImportError:
-            pass
+            # Guess encoding ourselves.
+            # These should be the most frequently used ones.
+            encodings = ('utf-8', 'utf-16')
+            for encoding in encodings:
+                try:
+                    with codecs.open(path, 'r', encoding=encoding) as fobj:
+                        text = fobj.read(count)
+                except UnicodeDecodeError:
+                    pass
+                else:
+                    LOG.debug("guessed encoding of '%s' as %r", path, encoding)
+                    return text
         else:
             with open(path, 'rb') as fobj:
                 data = fobj.read(count)
@@ -1180,18 +1191,6 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
                 LOG.debug("chardet guess for '%s': %s", path, result)
                 return codecs.decode(data, guessed_encoding, 'replace')
 
-        # Guess encoding ourselves. These should be the most frequently used ones.
-        encodings = ('utf-8', 'utf-16')
-        for encoding in encodings:
-            try:
-                with codecs.open(path, 'r', encoding=encoding) as fobj:
-                    text = fobj.read(count)
-            except UnicodeDecodeError:
-                pass
-            else:
-                LOG.debug("guessed encoding of '%s' as %r", path, encoding)
-                return text
-
         # latin-1 as the last resort
         with codecs.open(path, 'r', encoding='latin-1', errors='replace') as fobj:
             return fobj.read(count)