summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-10 18:42:56 +0200
committerhut <hut@lavabit.com>2011-10-10 18:42:56 +0200
commitc32674664881fb5fc56e02f655b3dcc371c4365f (patch)
treeff0579edf5525714a87957d2d7d4ae81d2d5fd64
parent2d5efba042d2b8953f654907167b496450e1fe71 (diff)
downloadranger-c32674664881fb5fc56e02f655b3dcc371c4365f.tar.gz
gui.curses_shortcuts: simplifications
The UnicodeEncodeError hardly ever occurs anymore, since other
unicode fixes were implemented.  I see no reason to keep the
error handlers there.
-rw-r--r--ranger/gui/curses_shortcuts.py37
-rw-r--r--ranger/gui/ui.py5
2 files changed, 7 insertions, 35 deletions
diff --git a/ranger/gui/curses_shortcuts.py b/ranger/gui/curses_shortcuts.py
index bae03adc..f654ab11 100644
--- a/ranger/gui/curses_shortcuts.py
+++ b/ranger/gui/curses_shortcuts.py
@@ -21,22 +21,6 @@ from ranger.ext.iter_tools import flatten
 from ranger.gui.color import get_color
 from ranger.core.shared import SettingsAware
 
-def ascii_only(string):
-	# Some python versions have problems with invalid unicode strings.
-	# I think this exception is rare enough that this naive hack is enough.
-	# It simply removes all non-ascii chars from a string.
-	def validate_char(char):
-		try:
-			if ord(char) > 127:
-				return '?'
-		except:
-			return '?'
-		return char
-	if isinstance(string, str):
-		return ''.join(validate_char(c) for c in string)
-	return string
-
-
 class CursesShortcuts(SettingsAware):
 	"""
 	This class defines shortcuts to faciliate operations with curses.
@@ -50,35 +34,20 @@ class CursesShortcuts(SettingsAware):
 	def addstr(self, *args):
 		try:
 			self.win.addstr(*args)
-		except (_curses.error, TypeError):
+		except:
 			pass
-		except UnicodeEncodeError:
-			try:
-				self.win.addstr(*(ascii_only(obj) for obj in args))
-			except (_curses.error, TypeError):
-				pass
 
 	def addnstr(self, *args):
 		try:
 			self.win.addnstr(*args)
-		except (_curses.error, TypeError):
+		except:
 			pass
-		except UnicodeEncodeError:
-			try:
-				self.win.addnstr(*(ascii_only(obj) for obj in args))
-			except (_curses.error, TypeError):
-				pass
 
 	def addch(self, *args):
 		try:
 			self.win.addch(*args)
-		except (_curses.error, TypeError):
+		except:
 			pass
-		except UnicodeEncodeError:
-			try:
-				self.win.addch(*(ascii_only(obj) for obj in args))
-			except (_curses.error, TypeError):
-				pass
 
 	def color(self, *keys):
 		"""Change the colors from now on."""
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 1f3588f9..098f6a44 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -19,7 +19,6 @@ import curses
 import _curses
 
 from .displayable import DisplayableContainer
-from ranger.gui.curses_shortcuts import ascii_only
 from .mouse_event import MouseEvent
 from ranger.ext.keybinding_parser import ALT_KEY
 
@@ -29,6 +28,10 @@ TERMINALS_WITH_TITLE = ("xterm", "xterm-256color", "rxvt",
 
 MOUSEMASK = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION
 
+_ASCII = ''.join(chr(c) for c in range(32, 127))
+def ascii_only(string):
+	return ''.join(c if c in _ASCII else '?' for c in string)
+
 def _setup_mouse(signal):
 	if signal['value']:
 		curses.mousemask(MOUSEMASK)