mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
make TeeOut and TeeErr private to module
This commit is contained in:
parent
d3a300d801
commit
588a3acd18
1 changed files with 19 additions and 9 deletions
|
@ -12,13 +12,13 @@ from xonsh.completer import Completer
|
||||||
from xonsh.environ import multiline_prompt, format_prompt
|
from xonsh.environ import multiline_prompt, format_prompt
|
||||||
|
|
||||||
|
|
||||||
class TeeOut(object):
|
class _TeeOut(object):
|
||||||
"""Tees stdout into the original sys.stdout and another buffer."""
|
"""Tees stdout into the original sys.stdout and another buffer."""
|
||||||
|
|
||||||
def __init__(self, buf, *args, **kwargs):
|
def __init__(self, buf):
|
||||||
_, _ = args, kwargs
|
|
||||||
self.buffer = buf
|
self.buffer = buf
|
||||||
self.stdout = sys.stdout
|
self.stdout = sys.stdout
|
||||||
|
self.encoding = self.stdout.encoding
|
||||||
sys.stdout = self
|
sys.stdout = self
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
@ -38,14 +38,19 @@ class TeeOut(object):
|
||||||
self.stdout.flush()
|
self.stdout.flush()
|
||||||
self.buffer.flush()
|
self.buffer.flush()
|
||||||
|
|
||||||
|
def fileno(self):
|
||||||
|
"""Tunnel fileno() calls."""
|
||||||
|
_ = self
|
||||||
|
return sys.stdout.fileno()
|
||||||
|
|
||||||
class TeeErr(object):
|
|
||||||
|
class _TeeErr(object):
|
||||||
"""Tees stderr into the original sys.stdout and another buffer."""
|
"""Tees stderr into the original sys.stdout and another buffer."""
|
||||||
|
|
||||||
def __init__(self, buf, *args, **kwargs):
|
def __init__(self, buf):
|
||||||
_, _ = args, kwargs
|
|
||||||
self.buffer = buf
|
self.buffer = buf
|
||||||
self.stderr = sys.stderr
|
self.stderr = sys.stderr
|
||||||
|
self.encoding = self.stderr.encoding
|
||||||
sys.stderr = self
|
sys.stderr = self
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
@ -65,6 +70,11 @@ class TeeErr(object):
|
||||||
self.stderr.flush()
|
self.stderr.flush()
|
||||||
self.buffer.flush()
|
self.buffer.flush()
|
||||||
|
|
||||||
|
def fileno(self):
|
||||||
|
"""Tunnel fileno() calls."""
|
||||||
|
_ = self
|
||||||
|
return sys.stderr.fileno()
|
||||||
|
|
||||||
|
|
||||||
class Tee(io.StringIO):
|
class Tee(io.StringIO):
|
||||||
"""Class that merges tee'd stdout and stderr into a single buffer.
|
"""Class that merges tee'd stdout and stderr into a single buffer.
|
||||||
|
@ -76,8 +86,8 @@ class Tee(io.StringIO):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.stdout = TeeOut(self)
|
self.stdout = _TeeOut(self)
|
||||||
self.stderr = TeeErr(self)
|
self.stderr = _TeeErr(self)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
del self.stdout, self.stderr
|
del self.stdout, self.stderr
|
||||||
|
@ -119,7 +129,7 @@ class BaseShell(object):
|
||||||
return
|
return
|
||||||
hist = builtins.__xonsh_history__ # pylint: disable=no-member
|
hist = builtins.__xonsh_history__ # pylint: disable=no-member
|
||||||
ts1 = None
|
ts1 = None
|
||||||
store_stdout = builtins.__xonsh_env__.get('XONSH_STORE_STDOUT', False) # pylint: disable=no-member
|
store_stdout = builtins.__xonsh_env__.get('XONSH_STORE_STDOUT') # pylint: disable=no-member
|
||||||
tee = Tee() if store_stdout else io.StringIO()
|
tee = Tee() if store_stdout else io.StringIO()
|
||||||
try:
|
try:
|
||||||
ts0 = time.time()
|
ts0 = time.time()
|
||||||
|
|
Loading…
Add table
Reference in a new issue