MCPcopy Create free account
hub / github.com/secdev/scapy / StringWriter

Class StringWriter

scapy/autorun.py:129–150  ·  view source on GitHub ↗

Util to mock sys.stdout and sys.stderr, and store their output in a 's' var.

Source from the content-addressed store, hash-verified

127
128
129class StringWriter(StringIO):
130 """Util to mock sys.stdout and sys.stderr, and
131 store their output in a 's' var."""
132 def __init__(self, debug=None):
133 # type: (Optional[TextIO]) -> None
134 self.s = ""
135 self.debug = debug
136 super().__init__()
137
138 def write(self, x):
139 # type: (str) -> int
140 # Object can be in the middle of being destroyed.
141 if getattr(self, "debug", None) and self.debug:
142 self.debug.write(x)
143 if getattr(self, "s", None) is not None:
144 self.s += x
145 return len(x)
146
147 def flush(self):
148 # type: () -> None
149 if getattr(self, "debug", None) and self.debug:
150 self.debug.flush()
151
152
153def autorun_get_interactive_session(cmds, **kargs):

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…