mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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.
This commit is contained in:
parent
9d72bb452b
commit
2fa74bbad5
1 changed files with 23 additions and 0 deletions
23
Lib/site.py
23
Lib/site.py
|
@ -400,6 +400,28 @@ def execsitecustomize():
|
||||||
(err.__class__.__name__, err))
|
(err.__class__.__name__, err))
|
||||||
|
|
||||||
|
|
||||||
|
def installnewio():
|
||||||
|
"""Install new I/O library as default.
|
||||||
|
|
||||||
|
This is only done if $PYTHONNEWIO is set and non-empty.
|
||||||
|
"""
|
||||||
|
if not os.getenv("PYTHONNEWIO"):
|
||||||
|
return
|
||||||
|
import io
|
||||||
|
# Trick so that open won't become a bound method when stored
|
||||||
|
# as a class variable (as dumbdbm does)
|
||||||
|
class open:
|
||||||
|
def __new__(cls, *args, **kwds):
|
||||||
|
return io.open(*args, **kwds)
|
||||||
|
__builtin__.classic_open = __builtin__.open
|
||||||
|
__builtin__.classic_file = __builtin__.file
|
||||||
|
__builtin__.open = open
|
||||||
|
__builtin__.file = open
|
||||||
|
sys.stdin = io.open(0, "r")
|
||||||
|
sys.stdout = io.open(1, "w")
|
||||||
|
sys.stderr = io.open(2, "w")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
abs__file__()
|
abs__file__()
|
||||||
paths_in_sys = removeduppaths()
|
paths_in_sys = removeduppaths()
|
||||||
|
@ -414,6 +436,7 @@ def main():
|
||||||
sethelper()
|
sethelper()
|
||||||
aliasmbcs()
|
aliasmbcs()
|
||||||
setencoding()
|
setencoding()
|
||||||
|
installnewio()
|
||||||
execsitecustomize()
|
execsitecustomize()
|
||||||
# Remove sys.setdefaultencoding() so that users cannot change the
|
# Remove sys.setdefaultencoding() so that users cannot change the
|
||||||
# encoding after initialization. The test for presence is needed when
|
# encoding after initialization. The test for presence is needed when
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue