From e58f8b59b79f0419cb471cb7430df98530872567 Mon Sep 17 00:00:00 2001 From: Eric Shull Date: Thu, 8 Nov 2012 13:36:33 -0500 Subject: [PATCH] Add isatty method to LazyWriter. --- gunicorn/glogging.py | 3 +++ tests/test_005-lazywriter-isatty.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/test_005-lazywriter-isatty.py diff --git a/gunicorn/glogging.py b/gunicorn/glogging.py index eaa82708..d15925fd 100644 --- a/gunicorn/glogging.py +++ b/gunicorn/glogging.py @@ -87,6 +87,9 @@ class LazyWriter(object): def flush(self): self.open().flush() + def isatty(self): + return bool(self.fileobj and self.fileobj.isatty()) + class SafeAtoms(dict): def __init__(self, atoms): diff --git a/tests/test_005-lazywriter-isatty.py b/tests/test_005-lazywriter-isatty.py new file mode 100644 index 00000000..50cc71c9 --- /dev/null +++ b/tests/test_005-lazywriter-isatty.py @@ -0,0 +1,13 @@ +import sys + +from gunicorn.glogging import LazyWriter + + +def test_lazywriter_isatty(): + orig = sys.stdout + sys.stdout = LazyWriter('test.log') + try: + sys.stdout.isatty() + except AttributeError: + raise AssertionError("LazyWriter has no attribute 'isatty'") + sys.stdout = orig