]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add an encoding property to TextIOBase instances.
authorGuido van Rossum <guido@python.org>
Thu, 24 May 2007 17:58:06 +0000 (17:58 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 24 May 2007 17:58:06 +0000 (17:58 +0000)
Add sys.__std{in,out,err}__.
Make test_sys pass.

Lib/io.py
Lib/site.py

index 072b756e0dabdff738035643e2d05763565ca2f6..67049e63b441e8147d791d17a0941aa7b2ee4d8a 100644 (file)
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -925,6 +925,11 @@ class TextIOBase(IOBase):
             raise StopIteration
         return line
 
+    @property
+    def encoding(self):
+        """Subclasses should override."""
+        return None
+
     # The following are provided for backwards compatibility
 
     def readlines(self, hint=None):
@@ -970,6 +975,10 @@ class TextIOWrapper(TextIOBase):
         self._snapshot = None
         self._seekable = self._telling = self.buffer.seekable()
 
+    @property
+    def encoding(self):
+        return self._encoding
+
     # A word about _snapshot.  This attribute is either None, or a
     # tuple (decoder_state, readahead, pending) where decoder_state is
     # the second (integer) item of the decoder state, readahead is the
index e00890ead972a25ce59780b6e3195707deac1c8d..f7ca83b3805c9ab63de520c9d7eebef2759e02f1 100644 (file)
@@ -411,9 +411,9 @@ def installnewio():
         def __new__(cls, *args, **kwds):
             return io.open(*args, **kwds)
     __builtin__.open = open
-    sys.stdin = io.open(0, "r")
-    sys.stdout = io.open(1, "w")
-    sys.stderr = io.open(2, "w")
+    sys.__stdin__ = sys.stdin = io.open(0, "r")
+    sys.__stdout__ = sys.stdout = io.open(1, "w")
+    sys.__stderr__ = sys.stderr = io.open(2, "w")
 
 
 def main():