@@ -346,8 +346,7 @@ def __init__(self, stream, errors='strict'):
346346
347347 """ Creates a StreamWriter instance.
348348
349- stream must be a file-like object open for writing
350- (binary) data.
349+ stream must be a file-like object open for writing.
351350
352351 The StreamWriter may use different error handling
353352 schemes by providing the errors keyword argument. These
@@ -421,8 +420,7 @@ def __init__(self, stream, errors='strict'):
421420
422421 """ Creates a StreamReader instance.
423422
424- stream must be a file-like object open for reading
425- (binary) data.
423+ stream must be a file-like object open for reading.
426424
427425 The StreamReader may use different error handling
428426 schemes by providing the errors keyword argument. These
@@ -450,13 +448,12 @@ def read(self, size=-1, chars=-1, firstline=False):
450448 """ Decodes data from the stream self.stream and returns the
451449 resulting object.
452450
453- chars indicates the number of characters to read from the
454- stream. read() will never return more than chars
455- characters, but it might return less, if there are not enough
456- characters available.
451+ chars indicates the number of decoded code points or bytes to
452+ return. read() will never return more data than requested,
453+ but it might return less, if there is not enough available.
457454
458- size indicates the approximate maximum number of bytes to
459- read from the stream for decoding purposes . The decoder
455+ size indicates the approximate maximum number of decoded
456+ bytes or code points to read for decoding. The decoder
460457 can modify this setting as appropriate. The default value
461458 -1 indicates to read and decode as much as possible. size
462459 is intended to prevent having to decode huge files in one
@@ -467,7 +464,7 @@ def read(self, size=-1, chars=-1, firstline=False):
467464 will be returned, the rest of the input will be kept until the
468465 next call to read().
469466
470- The method should use a greedy read strategy meaning that
467+ The method should use a greedy read strategy, meaning that
471468 it should read as much data as is allowed within the
472469 definition of the encoding and the given size, e.g. if
473470 optional encoding endings or state markers are available
@@ -602,7 +599,7 @@ def readline(self, size=None, keepends=True):
602599 def readlines (self , sizehint = None , keepends = True ):
603600
604601 """ Read all lines available on the input stream
605- and return them as list of lines .
602+ and return them as a list .
606603
607604 Line breaks are implemented using the codec's decoder
608605 method and are included in the list entries.
@@ -750,19 +747,18 @@ def __exit__(self, type, value, tb):
750747
751748class StreamRecoder :
752749
753- """ StreamRecoder instances provide a frontend - backend
754- view of encoding data.
750+ """ StreamRecoder instances translate data from one encoding to another.
755751
756752 They use the complete set of APIs returned by the
757753 codecs.lookup() function to implement their task.
758754
759- Data written to the stream is first decoded into an
760- intermediate format (which is dependent on the given codec
761- combination) and then written to the stream using an instance
762- of the provided Writer class.
755+ Data written to the StreamRecoder is first decoded into an
756+ intermediate format (depending on the "decode" codec) and then
757+ written to the underlying stream using an instance of the provided
758+ Writer class.
763759
764- In the other direction, data is read from the stream using a
765- Reader instance and then return encoded data to the caller.
760+ In the other direction, data is read from the underlying stream using
761+ a Reader instance and then encoded and returned to the caller.
766762
767763 """
768764 # Optional attributes set by the file wrappers below
@@ -774,22 +770,17 @@ def __init__(self, stream, encode, decode, Reader, Writer,
774770
775771 """ Creates a StreamRecoder instance which implements a two-way
776772 conversion: encode and decode work on the frontend (the
777- input to .read() and output of .write()) while
778- Reader and Writer work on the backend (reading and
779- writing to the stream).
773+ data visible to .read() and .write()) while Reader and Writer
774+ work on the backend (the data in stream).
780775
781- You can use these objects to do transparent direct
782- recodings from e.g. latin-1 to utf-8 and back.
776+ You can use these objects to do transparent
777+ transcodings from e.g. latin-1 to utf-8 and back.
783778
784779 stream must be a file-like object.
785780
786- encode, decode must adhere to the Codec interface, Reader,
781+ encode and decode must adhere to the Codec interface; Reader and
787782 Writer must be factory functions or classes providing the
788- StreamReader, StreamWriter interface resp.
789-
790- encode and decode are needed for the frontend translation,
791- Reader and Writer for the backend translation. Unicode is
792- used as intermediate encoding.
783+ StreamReader and StreamWriter interfaces resp.
793784
794785 Error handling is done in the same way as defined for the
795786 StreamWriter/Readers.
@@ -864,7 +855,7 @@ def __exit__(self, type, value, tb):
864855
865856### Shortcuts
866857
867- def open (filename , mode = 'rb ' , encoding = None , errors = 'strict' , buffering = 1 ):
858+ def open (filename , mode = 'r ' , encoding = None , errors = 'strict' , buffering = 1 ):
868859
869860 """ Open an encoded file using the given mode and return
870861 a wrapped version providing transparent encoding/decoding.
@@ -874,10 +865,8 @@ def open(filename, mode='rb', encoding=None, errors='strict', buffering=1):
874865 codecs. Output is also codec dependent and will usually be
875866 Unicode as well.
876867
877- Files are always opened in binary mode, even if no binary mode
878- was specified. This is done to avoid data loss due to encodings
879- using 8-bit values. The default file mode is 'rb' meaning to
880- open the file in binary read mode.
868+ Underlying encoded files are always opened in binary mode.
869+ The default file mode is 'r', meaning to open the file in read mode.
881870
882871 encoding specifies the encoding which is to be used for the
883872 file.
@@ -913,13 +902,13 @@ def EncodedFile(file, data_encoding, file_encoding=None, errors='strict'):
913902 """ Return a wrapped version of file which provides transparent
914903 encoding translation.
915904
916- Strings written to the wrapped file are interpreted according
917- to the given data_encoding and then written to the original
918- file as string using file_encoding. The intermediate encoding
905+ Data written to the wrapped file is decoded according
906+ to the given data_encoding and then encoded to the underlying
907+ file using file_encoding. The intermediate data type
919908 will usually be Unicode but depends on the specified codecs.
920909
921- Strings are read from the file using file_encoding and then
922- passed back to the caller as string using data_encoding.
910+ Bytes read from the file are decoded using file_encoding and then
911+ passed back to the caller encoded using data_encoding.
923912
924913 If file_encoding is not given, it defaults to data_encoding.
925914
0 commit comments