From 605457cb5854e99282f58ec79cccd0ec6564235c Mon Sep 17 00:00:00 2001 From: Erik Rose Date: Mon, 7 Nov 2011 02:40:01 -0800 Subject: Stop crashing when piping to other programs. Bump version to 1.0.1. --- README.rst | 4 ++++ setup.py | 2 +- terminator/__init__.py | 4 +++- terminator/tests.py | 16 ++++++++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 1eb59dd..83aaf1a 100644 --- a/README.rst +++ b/README.rst @@ -177,6 +177,10 @@ Bugs or suggestions? Visit the `issue tracker`_. Version History =============== +1.0.1 + * Fixed a crash when piping output to other programs. Funny how the very act + of releasing software causes bugs to emerge, isn't it? + 1.0 * Extracted Terminator from nose-progressive, my `progress-bar-having, traceback-shortcutting, rootin', tootin' testrunner`_. It provided the diff --git a/setup.py b/setup.py index c0490fc..9ca6184 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ if sys.version_info >= (3,): setup( name='terminator', - version='1.0', + version='1.0.1', description='A thin, practical wrapper around terminal capabilities', long_description=open('README.rst').read(), author='Erik Rose', diff --git a/terminator/__init__.py b/terminator/__init__.py index b11b47c..481d411 100644 --- a/terminator/__init__.py +++ b/terminator/__init__.py @@ -35,7 +35,9 @@ class Terminal(object): """ if stream is None: stream = sys.__stdout__ - if hasattr(stream, 'fileno') and isatty(stream.fileno()): + if (hasattr(stream, 'fileno') and + callable(stream.fileno) and + isatty(stream.fileno())): # Make things like tigetstr() work: # (Explicit args make setupterm() work even when -s is passed.) setupterm(kind or environ.get('TERM', 'unknown'), diff --git a/terminator/tests.py b/terminator/tests.py index 0efe6e9..431238f 100644 --- a/terminator/tests.py +++ b/terminator/tests.py @@ -1,4 +1,4 @@ -from cStringIO import StringIO +from StringIO import StringIO from curses import tigetstr, tparm import sys @@ -52,7 +52,7 @@ def test_location(): # Then rip it away, replacing it with something we can check later: output = t.stream = StringIO() - + with t.location(3, 4): output.write('hi') @@ -60,3 +60,15 @@ def test_location(): tparm(tigetstr('cup'), 4, 3) + 'hi' + tigetstr('rc')) + + +def test_null_fileno(): + """Make sure ``Terinal`` works when ``fileno`` is ``None``. + + This simulates piping output to another program. + + """ + out = stream=StringIO() + out.fileno = None + t = Terminal(stream=out) + eq_(t.save, '') -- cgit v1.2.1