summaryrefslogtreecommitdiff
path: root/blessings
diff options
context:
space:
mode:
authorjquast <contact@jeffquast.com>2013-09-09 07:54:19 -0400
committerjquast <contact@jeffquast.com>2013-09-09 07:54:19 -0400
commit0c3612af72e07d17ad5d4f5d7f8b457f2fadc9f4 (patch)
tree6e44a26d252bec7e455fe4630969caa0dca05340 /blessings
parent9068e52c388014d805c9b20aacb57b1af7491858 (diff)
downloadblessings-0c3612af72e07d17ad5d4f5d7f8b457f2fadc9f4.tar.gz
rollback undesired changes per feedback
- remove module-level docstring (but? pep-257, "All modules should normally have docstrings" ??) - try to restore original import ordering (unused imports remain removed) - restore deep import of os environ, isatty - restore "caching doesn't work" scrap code
Diffstat (limited to 'blessings')
-rw-r--r--blessings/__init__.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py
index 673fa26..abf44c1 100644
--- a/blessings/__init__.py
+++ b/blessings/__init__.py
@@ -1,17 +1,7 @@
-"""
-(c) 2012 Erik Rose
-MIT Licensed
-https://github.com/erikrose/blessings
-"""
-import curses
-import os
-import struct
-import sys
from contextlib import contextmanager
+import curses
from curses import setupterm, tigetnum, tigetstr, tparm
from fcntl import ioctl
-from platform import python_version_tuple
-from termios import TIOCGWINSZ
try:
from io import UnsupportedOperation as IOUnsupportedOperation
@@ -20,6 +10,12 @@ except ImportError:
"""A dummy exception to take the place of Python 3's
``io.UnsupportedOperation`` in Python 2"""
+from os import isatty, environ
+from platform import python_version_tuple
+import struct
+import sys
+from termios import TIOCGWINSZ
+
__all__ = ['Terminal']
@@ -80,12 +76,13 @@ class Terminal(object):
stream = sys.__stdout__
try:
stream_descriptor = (stream.fileno() if hasattr(stream, 'fileno')
- and callable(stream.fileno) else None)
+ and callable(stream.fileno)
+ else None)
except IOUnsupportedOperation:
stream_descriptor = None
self._is_a_tty = (stream_descriptor is not None and
- os.isatty(stream_descriptor))
+ isatty(stream_descriptor))
self._does_styling = ((self.is_a_tty or force_styling) and
force_styling is not None)
@@ -101,7 +98,7 @@ class Terminal(object):
# init sequences to the stream if it has a file descriptor, and
# send them to stdout as a fallback, since they have to go
# somewhere.
- setupterm(kind or os.environ.get('TERM', 'unknown'),
+ setupterm(kind or environ.get('TERM', 'unknown'),
self._init_descriptor)
self.stream = stream
@@ -327,6 +324,8 @@ class Terminal(object):
# access to it.
colors = tigetnum('colors') # Returns -1 if no color support, -2 if no
# such cap.
+ # self.__dict__['colors'] = ret # Cache it. It's not changing.
+ # (Doesn't work.)
return colors if colors >= 0 else 0
def _resolve_formatter(self, attr):