summaryrefslogtreecommitdiff
path: root/blessings/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'blessings/__init__.py')
-rw-r--r--blessings/__init__.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py
index be71d0b..333d68e 100644
--- a/blessings/__init__.py
+++ b/blessings/__init__.py
@@ -2,6 +2,12 @@ from collections import defaultdict
import curses
from curses import tigetstr, setupterm, tparm
from fcntl import ioctl
+try:
+ from io import UnsupportedOperation as IOUnsupportedOperation
+except ImportError:
+ class IOUnsupportedOperation(Exception):
+ """A dummy exception to take the place of Python 3's io.UnsupportedOperation one in Python 2"""
+ pass
from os import isatty, environ
import struct
import sys
@@ -59,9 +65,12 @@ class Terminal(object):
"""
if stream is None:
stream = sys.__stdout__
- stream_descriptor = (stream.fileno() if hasattr(stream, 'fileno')
- and callable(stream.fileno)
- else None)
+ try:
+ stream_descriptor = (stream.fileno() if hasattr(stream, 'fileno')
+ and callable(stream.fileno)
+ else None)
+ except IOUnsupportedOperation:
+ stream_descriptor = None
self.is_a_tty = stream_descriptor is not None and isatty(stream_descriptor)
if self.is_a_tty or force_styling:
# The desciptor to direct terminal initialization sequences to.