MCPcopy Index your code
hub / github.com/python/cpython / StdIOBuffer

Class StdIOBuffer

Lib/test/test_argparse.py:36–51  ·  view source on GitHub ↗

Replacement for writable io.StringIO that behaves more like real file Unlike StringIO, provides a buffer attribute that holds the underlying binary data, allowing it to replace sys.stdout/sys.stderr in more contexts.

Source from the content-addressed store, hash-verified

34
35
36class StdIOBuffer(io.TextIOWrapper):
37 '''Replacement for writable io.StringIO that behaves more like real file
38
39 Unlike StringIO, provides a buffer attribute that holds the underlying
40 binary data, allowing it to replace sys.stdout/sys.stderr in more
41 contexts.
42 '''
43
44 def __init__(self, initial_value='', newline='\n'):
45 initial_value = initial_value.encode('utf-8')
46 super().__init__(io.BufferedWriter(io.BytesIO(initial_value)),
47 'utf-8', newline=newline)
48
49 def getvalue(self):
50 self.flush()
51 return self.buffer.raw.getvalue().decode('utf-8')
52
53
54class StdStreamTest(unittest.TestCase):

Callers 4

stderr_to_parser_errorFunction · 0.85
test_printMethod · 0.85
test_print_fileMethod · 0.85

Calls

no outgoing calls

Tested by 4

stderr_to_parser_errorFunction · 0.68
test_printMethod · 0.68
test_print_fileMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…