diff options
author | Guido van Rossum <guido@python.org> | 2007-04-17 21:49:04 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-04-17 21:49:04 (GMT) |
commit | 2fa74bbad5bf780b838b4da3ce827ae329ccddc1 (patch) | |
tree | 2b3b588ee13b55379562a0be5a8d08ae5d4c5086 /Lib | |
parent | 9d72bb452bced3a100f07f8a9e30c4495a9ec41a (diff) | |
download | cpython-2fa74bbad5bf780b838b4da3ce827ae329ccddc1.zip cpython-2fa74bbad5bf780b838b4da3ce827ae329ccddc1.tar.gz cpython-2fa74bbad5bf780b838b4da3ce827ae329ccddc1.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/site.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/site.py b/Lib/site.py index 95001ba..48cf385 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -400,6 +400,28 @@ def execsitecustomize(): (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(): abs__file__() paths_in_sys = removeduppaths() @@ -414,6 +436,7 @@ def main(): sethelper() aliasmbcs() setencoding() + installnewio() execsitecustomize() # Remove sys.setdefaultencoding() so that users cannot change the # encoding after initialization. The test for presence is needed when |