From 3020eb6852f91913b13ff7ad75f64d7d8914f973 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 20 Jul 2009 20:43:48 +0000 Subject: Use a lazy reference to sys.stdout, in case the API consumer has temporarily overridden stdout. svn path=/main/trunk/; revision=13840 --- pym/_emerge/JobStatusDisplay.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pym/_emerge/JobStatusDisplay.py b/pym/_emerge/JobStatusDisplay.py index 3511ccb5b..561b78c2d 100644 --- a/pym/_emerge/JobStatusDisplay.py +++ b/pym/_emerge/JobStatusDisplay.py @@ -44,8 +44,7 @@ class JobStatusDisplay(object): 'newline' : 'nel', } - def __init__(self, out=sys.stdout, quiet=False, xterm_titles=True): - object.__setattr__(self, "out", out) + def __init__(self, quiet=False, xterm_titles=True): object.__setattr__(self, "quiet", quiet) object.__setattr__(self, "xterm_titles", xterm_titles) object.__setattr__(self, "maxval", 0) @@ -56,7 +55,7 @@ class JobStatusDisplay(object): object.__setattr__(self, "width", 80) self.reset() - isatty = hasattr(out, "isatty") and out.isatty() + isatty = hasattr(self.out, "isatty") and self.out.isatty() object.__setattr__(self, "_isatty", isatty) if not isatty or not self._init_term(): term_codes = {} @@ -68,6 +67,12 @@ class JobStatusDisplay(object): if not isinstance(v, basestring): self._term_codes[k] = v.decode(encoding, 'replace') + @property + def out(self): + """Use a lazy reference to sys.stdout, in case the API consumer has + temporarily overridden stdout.""" + return sys.stdout + def _init_term(self): """ Initialize term control codes. -- cgit v1.2.3-1-g7c22