summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2017-01-25 18:08:49 +0100
committernfnty <git@nfnty.se>2017-01-25 18:13:13 +0100
commit3021188bcd12095c72e505e7d57d01c0dbf44a35 (patch)
tree5eea53e15eca8d0da7b30e7111a2b808624e3562
parente7f65ba6a2dc56dc3bf94107d98f0177f1ecc431 (diff)
downloadranger-3021188bcd12095c72e505e7d57d01c0dbf44a35.tar.gz
gui.widgets.pager: Handle `source.close()` exception
Fixes #315
-rw-r--r--ranger/gui/widgets/pager.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py
index bf7ca5f4..42adf1e9 100644
--- a/ranger/gui/widgets/pager.py
+++ b/ranger/gui/widgets/pager.py
@@ -6,6 +6,7 @@
 from __future__ import (absolute_import, division, print_function)
 
 import curses
+import logging
 
 from ranger.gui import ansi
 from ranger.ext.direction import Direction
@@ -13,9 +14,11 @@ from ranger.ext.img_display import ImgDisplayUnsupportedException
 
 from . import Widget
 
-# TODO: Scrolling in embedded pager
+
+LOG = logging.getLogger(__name__)
 
 
+# TODO: Scrolling in embedded pager
 class Pager(Widget):  # pylint: disable=too-many-instance-attributes
     source = None
     source_is_stream = False
@@ -37,6 +40,14 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         self.image = None
         self.image_drawn = False
 
+    def _close_source(self):
+        if self.source and self.source_is_stream:
+            try:
+                self.source.close()
+            except OSError as ex:
+                LOG.error('Unable to close pager source')
+                LOG.exception(ex)
+
     def open(self):
         self.scroll_begin = 0
         self.markup = None
@@ -54,8 +65,7 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         if self.image:
             self.need_clear_image = True
             self.clear_image()
-        if self.source and self.source_is_stream:
-            self.source.close()
+        self._close_source()
 
     def destroy(self):
         self.clear_image(force=True)
@@ -159,9 +169,7 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         if self.image:
             self.need_clear_image = True
         self.image = image
-
-        if self.source and self.source_is_stream:
-            self.source.close()
+        self._close_source()
         self.source = None
         self.source_is_stream = False
 
@@ -169,9 +177,7 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         if self.image:
             self.image = None
             self.need_clear_image = True
-
-        if self.source and self.source_is_stream:
-            self.source.close()
+        self._close_source()
 
         self.max_width = 0
         if isinstance(source, str):