Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2fa74bb

Browse files
committed
If $PYTHONNEWIO is set and nonempty,
io.py is used for open() and sys.std{in,out,err}. Note that this currently breaks about 25 tests.
1 parent 9d72bb4 commit 2fa74bb

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lib/site.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
403425
def 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

0 commit comments

Comments
 (0)