summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-02-15 23:55:06 +0100
committerhut <hut@lavabit.com>2013-02-15 23:55:06 +0100
commitc29059c87507bbcab6ca87b1bf1f396de6fc07f0 (patch)
tree2932c4f67ca26e6e6fd9c898c6cf7e53a24e21e7
parent3a0536e460e95b94409168a14a224e6f00d4c1fc (diff)
downloadranger-c29059c87507bbcab6ca87b1bf1f396de6fc07f0.tar.gz
ext.widestring: fix f*kups on WideString(<unicode object>)
-rw-r--r--ranger/ext/widestring.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/ranger/ext/widestring.py b/ranger/ext/widestring.py
index 88565b89..31e41210 100644
--- a/ranger/ext/widestring.py
+++ b/ranger/ext/widestring.py
@@ -53,7 +53,15 @@ def string_to_charlist(string):
 
 class WideString(object):
     def __init__(self, string, chars=None):
-        self.string = string
+        try:
+            self.string = str(string)
+        except UnicodeEncodeError:
+            # Here I assume that string is a "unicode" object, because why else
+            # would str(string) raise a UnicodeEncodeError?
+            try:
+                self.string = string.encode('latin-1', 'ignore')
+            except:
+                self.string = ""
         if chars is None:
             self.chars = string_to_charlist(string)
         else: