@@ -414,6 +414,9 @@ def __enter__(self):
414414 def __exit__ (self , type , value , tb ):
415415 self .stream .close ()
416416
417+ def __reduce_ex__ (self , proto ):
418+ raise TypeError ("can't serialize %s" % self .__class__ .__name__ )
419+
417420###
418421
419422class StreamReader (Codec ):
@@ -663,6 +666,9 @@ def __enter__(self):
663666 def __exit__ (self , type , value , tb ):
664667 self .stream .close ()
665668
669+ def __reduce_ex__ (self , proto ):
670+ raise TypeError ("can't serialize %s" % self .__class__ .__name__ )
671+
666672###
667673
668674class StreamReaderWriter :
@@ -750,6 +756,9 @@ def __enter__(self):
750756 def __exit__ (self , type , value , tb ):
751757 self .stream .close ()
752758
759+ def __reduce_ex__ (self , proto ):
760+ raise TypeError ("can't serialize %s" % self .__class__ .__name__ )
761+
753762###
754763
755764class StreamRecoder :
@@ -866,6 +875,9 @@ def __enter__(self):
866875 def __exit__ (self , type , value , tb ):
867876 self .stream .close ()
868877
878+ def __reduce_ex__ (self , proto ):
879+ raise TypeError ("can't serialize %s" % self .__class__ .__name__ )
880+
869881### Shortcuts
870882
871883def open (filename , mode = 'r' , encoding = None , errors = 'strict' , buffering = - 1 ):
@@ -878,7 +890,8 @@ def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):
878890 codecs. Output is also codec dependent and will usually be
879891 Unicode as well.
880892
881- Underlying encoded files are always opened in binary mode.
893+ If encoding is not None, then the
894+ underlying encoded files are always opened in binary mode.
882895 The default file mode is 'r', meaning to open the file in read mode.
883896
884897 encoding specifies the encoding which is to be used for the
@@ -1114,13 +1127,3 @@ def make_encoding_map(decoding_map):
11141127_false = 0
11151128if _false :
11161129 import encodings
1117-
1118- ### Tests
1119-
1120- if __name__ == '__main__' :
1121-
1122- # Make stdout translate Latin-1 output into UTF-8 output
1123- sys .stdout = EncodedFile (sys .stdout , 'latin-1' , 'utf-8' )
1124-
1125- # Have stdin translate Latin-1 input into UTF-8 input
1126- sys .stdin = EncodedFile (sys .stdin , 'utf-8' , 'latin-1' )
0 commit comments