File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -400,6 +400,28 @@ def execsitecustomize():
400400 (err .__class__ .__name__ , err ))
401401
402402
403+ def installnewio ():
404+ """Install new I/O library as default.
405+
406+ This is only done if $PYTHONNEWIO is set and non-empty.
407+ """
408+ if not os .getenv ("PYTHONNEWIO" ):
409+ return
410+ import io
411+ # Trick so that open won't become a bound method when stored
412+ # as a class variable (as dumbdbm does)
413+ class open :
414+ def __new__ (cls , * args , ** kwds ):
415+ return io .open (* args , ** kwds )
416+ __builtin__ .classic_open = __builtin__ .open
417+ __builtin__ .classic_file = __builtin__ .file
418+ __builtin__ .open = open
419+ __builtin__ .file = open
420+ sys .stdin = io .open (0 , "r" )
421+ sys .stdout = io .open (1 , "w" )
422+ sys .stderr = io .open (2 , "w" )
423+
424+
403425def main ():
404426 abs__file__ ()
405427 paths_in_sys = removeduppaths ()
@@ -414,6 +436,7 @@ def main():
414436 sethelper ()
415437 aliasmbcs ()
416438 setencoding ()
439+ installnewio ()
417440 execsitecustomize ()
418441 # Remove sys.setdefaultencoding() so that users cannot change the
419442 # encoding after initialization. The test for presence is needed when
You can’t perform that action at this time.
0 commit comments