diff options
author | Guido van Rossum <guido@python.org> | 2007-10-19 23:16:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-10-19 23:16:50 (GMT) |
commit | ce3a72aec6eaa0293c397c8d0407f7afe0072b2f (patch) | |
tree | 646cf27667087a48b908f330759fb94271b43f60 /Lib | |
parent | 75a902db7859a4751743e98530c5d96a672641be (diff) | |
download | cpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.zip cpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.tar.gz cpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.tar.bz2 |
Patch 1267 by Christian Heimes.
Move the initialization of sys.std{in,out,err} and __builtin__.open
to C code.
This solves the problem that "python -S" wouldn't work.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/io.py | 12 | ||||
-rw-r--r-- | Lib/site.py | 18 | ||||
-rw-r--r-- | Lib/test/test_imp.py | 7 |
3 files changed, 19 insertions, 18 deletions
@@ -178,6 +178,18 @@ def open(file, mode="r", buffering=None, encoding=None, newline=None): return text +class OpenWrapper: + """Wrapper for __builtin__.open + + Trick so that open won't become a bound method when stored + as a class variable (as dumbdbm does). + + See initstdio() in Python/pythonrun.c. + """ + def __new__(cls, *args, **kwargs): + return open(*args, **kwargs) + + class UnsupportedOperation(ValueError, IOError): pass diff --git a/Lib/site.py b/Lib/site.py index 53e859e..f1db89c 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -402,23 +402,6 @@ def execsitecustomize(): (err.__class__.__name__, err)) -def installnewio(): - """Install new I/O library as default.""" - import io - # Hack to avoid a nasty recursion issue when Python is invoked - # in verbose mode: pre-import the Latin-1 and UTF-8 codecs - from encodings import latin_1, utf_8 - # 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__.open = open - sys.__stdin__ = sys.stdin = io.open(0, "r", newline='\n') - sys.__stdout__ = sys.stdout = io.open(1, "w", newline='\n') - sys.__stderr__ = sys.stderr = io.open(2, "w", newline='\n') - - def main(): abs__file__() paths_in_sys = removeduppaths() @@ -433,7 +416,6 @@ 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 diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index 62b14e0..87efc33 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -38,9 +38,16 @@ class LockTests(unittest.TestCase): self.fail("release_lock() without lock should raise " "RuntimeError") +class ImportTests(unittest.TestCase): + + def test_find_module_encoding(self): + fd = imp.find_module("heapq")[0] + self.assertEqual(fd.encoding, "iso-8859-1") + def test_main(): test_support.run_unittest( LockTests, + ImportTests, ) if __name__ == "__main__": |