@@ -347,8 +347,7 @@ def __init__(self, stream, errors='strict'):
347347
348348 """ Creates a StreamWriter instance.
349349
350- stream must be a file-like object open for writing
351- (binary) data.
350+ stream must be a file-like object open for writing.
352351
353352 The StreamWriter may use different error handling
354353 schemes by providing the errors keyword argument. These
@@ -422,8 +421,7 @@ def __init__(self, stream, errors='strict'):
422421
423422 """ Creates a StreamReader instance.
424423
425- stream must be a file-like object open for reading
426- (binary) data.
424+ stream must be a file-like object open for reading.
427425
428426 The StreamReader may use different error handling
429427 schemes by providing the errors keyword argument. These
@@ -451,13 +449,12 @@ def read(self, size=-1, chars=-1, firstline=False):
451449 """ Decodes data from the stream self.stream and returns the
452450 resulting object.
453451
454- chars indicates the number of characters to read from the
455- stream. read() will never return more than chars
456- characters, but it might return less, if there are not enough
457- characters available.
452+ chars indicates the number of decoded code points or bytes to
453+ return. read() will never return more data than requested,
454+ but it might return less, if there is not enough available.
458455
459- size indicates the approximate maximum number of bytes to
460- read from the stream for decoding purposes . The decoder
456+ size indicates the approximate maximum number of decoded
457+ bytes or code points to read for decoding. The decoder
461458 can modify this setting as appropriate. The default value
462459 -1 indicates to read and decode as much as possible. size
463460 is intended to prevent having to decode huge files in one
@@ -468,7 +465,7 @@ def read(self, size=-1, chars=-1, firstline=False):
468465 will be returned, the rest of the input will be kept until the
469466 next call to read().
470467
471- The method should use a greedy read strategy meaning that
468+ The method should use a greedy read strategy, meaning that
472469 it should read as much data as is allowed within the
473470 definition of the encoding and the given size, e.g. if
474471 optional encoding endings or state markers are available
@@ -603,7 +600,7 @@ def readline(self, size=None, keepends=True):
603600 def readlines (self , sizehint = None , keepends = True ):
604601
605602 """ Read all lines available on the input stream
606- and return them as list of lines .
603+ and return them as a list .
607604
608605 Line breaks are implemented using the codec's decoder
609606 method and are included in the list entries.
@@ -751,19 +748,18 @@ def __exit__(self, type, value, tb):
751748
752749class StreamRecoder :
753750
754- """ StreamRecoder instances provide a frontend - backend
755- view of encoding data.
751+ """ StreamRecoder instances translate data from one encoding to another.
756752
757753 They use the complete set of APIs returned by the
758754 codecs.lookup() function to implement their task.
759755
760- Data written to the stream is first decoded into an
761- intermediate format (which is dependent on the given codec
762- combination) and then written to the stream using an instance
763- of the provided Writer class.
756+ Data written to the StreamRecoder is first decoded into an
757+ intermediate format (depending on the "decode" codec) and then
758+ written to the underlying stream using an instance of the provided
759+ Writer class.
764760
765- In the other direction, data is read from the stream using a
766- Reader instance and then return encoded data to the caller.
761+ In the other direction, data is read from the underlying stream using
762+ a Reader instance and then encoded and returned to the caller.
767763
768764 """
769765 # Optional attributes set by the file wrappers below
@@ -775,22 +771,17 @@ def __init__(self, stream, encode, decode, Reader, Writer,
775771
776772 """ Creates a StreamRecoder instance which implements a two-way
777773 conversion: encode and decode work on the frontend (the
778- input to .read() and output of .write()) while
779- Reader and Writer work on the backend (reading and
780- writing to the stream).
774+ data visible to .read() and .write()) while Reader and Writer
775+ work on the backend (the data in stream).
781776
782- You can use these objects to do transparent direct
783- recodings from e.g. latin-1 to utf-8 and back.
777+ You can use these objects to do transparent
778+ transcodings from e.g. latin-1 to utf-8 and back.
784779
785780 stream must be a file-like object.
786781
787- encode, decode must adhere to the Codec interface, Reader,
782+ encode and decode must adhere to the Codec interface; Reader and
788783 Writer must be factory functions or classes providing the
789- StreamReader, StreamWriter interface resp.
790-
791- encode and decode are needed for the frontend translation,
792- Reader and Writer for the backend translation. Unicode is
793- used as intermediate encoding.
784+ StreamReader and StreamWriter interfaces resp.
794785
795786 Error handling is done in the same way as defined for the
796787 StreamWriter/Readers.
@@ -865,7 +856,7 @@ def __exit__(self, type, value, tb):
865856
866857### Shortcuts
867858
868- def open (filename , mode = 'rb ' , encoding = None , errors = 'strict' , buffering = 1 ):
859+ def open (filename , mode = 'r ' , encoding = None , errors = 'strict' , buffering = 1 ):
869860
870861 """ Open an encoded file using the given mode and return
871862 a wrapped version providing transparent encoding/decoding.
@@ -875,10 +866,8 @@ def open(filename, mode='rb', encoding=None, errors='strict', buffering=1):
875866 codecs. Output is also codec dependent and will usually be
876867 Unicode as well.
877868
878- Files are always opened in binary mode, even if no binary mode
879- was specified. This is done to avoid data loss due to encodings
880- using 8-bit values. The default file mode is 'rb' meaning to
881- open the file in binary read mode.
869+ Underlying encoded files are always opened in binary mode.
870+ The default file mode is 'r', meaning to open the file in read mode.
882871
883872 encoding specifies the encoding which is to be used for the
884873 file.
@@ -914,13 +903,13 @@ def EncodedFile(file, data_encoding, file_encoding=None, errors='strict'):
914903 """ Return a wrapped version of file which provides transparent
915904 encoding translation.
916905
917- Strings written to the wrapped file are interpreted according
918- to the given data_encoding and then written to the original
919- file as string using file_encoding. The intermediate encoding
906+ Data written to the wrapped file is decoded according
907+ to the given data_encoding and then encoded to the underlying
908+ file using file_encoding. The intermediate data type
920909 will usually be Unicode but depends on the specified codecs.
921910
922- Strings are read from the file using file_encoding and then
923- passed back to the caller as string using data_encoding.
911+ Bytes read from the file are decoded using file_encoding and then
912+ passed back to the caller encoded using data_encoding.
924913
925914 If file_encoding is not given, it defaults to data_encoding.
926915
0 commit comments