Debug Tools
TeeNoFile Class Reference
Inheritance diagram for TeeNoFile:
Collaboration diagram for TeeNoFile:

Public Member Functions

def __init__ (self, stdout=False, ignoredefault=False)
 
def closed (self)
 
def __del__ (self)
 
def clear (self, log=None)
 
def flush (self)
 
def writeboth (self, args, kwargs)
 
def writethis (self, args, kwargs)
 
def contents (self, date_regex="")
 
def file_contents (self, log, date_regex="")
 
def close (self)
 

Public Attributes

 stdout_type
 
 write
 

Static Public Attributes

def write = writeboth
 

Detailed Description

    How do I duplicate sys.stdout to a log file in python?
    https://stackoverflow.com/questions/616645/how-do-i-duplicate-sys-stdout-to-a-log-file-in-python

Definition at line 47 of file std_capture.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  stdout = False,
  ignoredefault = False 
)
If `ignoredefault` is True, only write to this object stream.

Definition at line 54 of file std_capture.py.

References TeeNoFile._contents, TeeNoFile._std_original, TeeNoFile.stdout_type, TeeNoFile.write, TeeNoFile.writeboth(), and TeeNoFile.writethis().

54  def __init__(self, stdout=False, ignoredefault=False):
55  """ If `ignoredefault` is True, only write to this object stream.
56  """
57  self._contents = []
58  self.stdout_type = stdout
59 
60  if stdout:
61  self._std_original = sys.stdout
62  sys.stdout = self
63 
64  else:
65  self._std_original = sys.stderr
66  sys.stderr = self
67 
68  if ignoredefault:
69  self.write = self.writethis
70  else:
71  self.write = self.writeboth
72 
73  # sys.stdout.write( "inspect.getmro(sys.stderr): %s\n" % str( inspect.getmro( type( sys.stderr ) ) ) )
74  # sys.stdout.write( "inspect.getmro(self.stderr): %s\n" % str( inspect.getmro( type( self._std_original ) ) ) )
75 
Here is the call graph for this function:

◆ __del__()

def __del__ (   self)
    The try/except block is in case this is called at program exit time, when it's possible
    that globals have already been deleted, and then the close() call might fail.  Since
    there's nothing we can do about such failures and they annoy the end users, we suppress
    the traceback.
    https://github.com/python/cpython/blob/1fd06f1eca80dcbf3a916133919482a8327f3da4/Lib/_pyio.py#L380

    python Exception AttributeError: “'NoneType' object has no attribute 'var'”
    https://stackoverflow.com/questions/9750308/python-exception-attributeerror-nonetype-object-has-no-attribute-var

Definition at line 83 of file std_capture.py.

References TeeNoFile.__closed, TeeNoFile._contents, TeeNoFile._process_contents(), TeeNoFile._std_original, TeeNoFile.close(), TeeNoFile.closed(), TeeNoFile.flush(), and TeeNoFile.stdout_type.

83  def __del__(self):
84  """
85  The try/except block is in case this is called at program exit time, when it's possible
86  that globals have already been deleted, and then the close() call might fail. Since
87  there's nothing we can do about such failures and they annoy the end users, we suppress
88  the traceback.
89  https://github.com/python/cpython/blob/1fd06f1eca80dcbf3a916133919482a8327f3da4/Lib/_pyio.py#L380
90 
91  python Exception AttributeError: “'NoneType' object has no attribute 'var'”
92  https://stackoverflow.com/questions/9750308/python-exception-attributeerror-nonetype-object-has-no-attribute-var
93  """
94 
95  try:
96  self.close()
97 
98  except:
99  pass
100 
Here is the call graph for this function:

Member Function Documentation

◆ closed()

def closed (   self)
    @return `True` if the file has been closed.

Definition at line 77 of file std_capture.py.

References TeeNoFile.__closed.

Referenced by TeeNoFile.__del__().

77  def closed(self):
78  """
79  @return `True` if the file has been closed.
80  """
81  return self.__closed
82 
Here is the caller graph for this function:

The documentation for this class was generated from the following file: