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

Class StreamReaderWriter

Lib/codecs.py:677–763  ·  view source on GitHub ↗

StreamReaderWriter instances allow wrapping streams which work in both read and write modes. The design is such that one can use the factory functions returned by the codec.lookup() function to construct the instance.

Source from the content-addressed store, hash-verified

675###
676
677class StreamReaderWriter:
678
679 """ StreamReaderWriter instances allow wrapping streams which
680 work in both read and write modes.
681
682 The design is such that one can use the factory functions
683 returned by the codec.lookup() function to construct the
684 instance.
685
686 """
687 # Optional attributes set by the file wrappers below
688 encoding = 'unknown'
689
690 def __init__(self, stream, Reader, Writer, errors='strict'):
691
692 """ Creates a StreamReaderWriter instance.
693
694 stream must be a Stream-like object.
695
696 Reader, Writer must be factory functions or classes
697 providing the StreamReader, StreamWriter interface resp.
698
699 Error handling is done in the same way as defined for the
700 StreamWriter/Readers.
701
702 """
703 self.stream = stream
704 self.reader = Reader(stream, errors)
705 self.writer = Writer(stream, errors)
706 self.errors = errors
707
708 def read(self, size=-1):
709
710 return self.reader.read(size)
711
712 def readline(self, size=None, keepends=True):
713
714 return self.reader.readline(size, keepends)
715
716 def readlines(self, sizehint=None, keepends=True):
717
718 return self.reader.readlines(sizehint, keepends)
719
720 def __next__(self):
721
722 """ Return the next decoded line from the input stream."""
723 return next(self.reader)
724
725 def __iter__(self):
726 return self
727
728 def write(self, data):
729
730 return self.writer.write(data)
731
732 def writelines(self, list):
733
734 return self.writer.writelines(list)

Callers 1

openFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…