[Python-checkins] r80752 - python/trunk/Lib/_pyio.py

victor.stinner python-checkins at python.org
Tue May 4 13:35:36 CEST 2010


Author: victor.stinner
Date: Tue May  4 13:35:36 2010
New Revision: 80752

Log:
_pyio: Fix TextIOWrapper constructor: os has no device_encoding() function

_io module doesn't call this function which was introduced in Python3.


Modified:
   python/trunk/Lib/_pyio.py

Modified: python/trunk/Lib/_pyio.py
==============================================================================
--- python/trunk/Lib/_pyio.py	(original)
+++ python/trunk/Lib/_pyio.py	Tue May  4 13:35:36 2010
@@ -1438,17 +1438,12 @@
             raise ValueError("illegal newline value: %r" % (newline,))
         if encoding is None:
             try:
-                encoding = os.device_encoding(buffer.fileno())
-            except (AttributeError, UnsupportedOperation):
-                pass
-            if encoding is None:
-                try:
-                    import locale
-                except ImportError:
-                    # Importing locale may fail if Python is being built
-                    encoding = "ascii"
-                else:
-                    encoding = locale.getpreferredencoding()
+                import locale
+            except ImportError:
+                # Importing locale may fail if Python is being built
+                encoding = "ascii"
+            else:
+                encoding = locale.getpreferredencoding()
 
         if not isinstance(encoding, basestring):
             raise ValueError("invalid encoding: %r" % encoding)


More information about the Python-checkins mailing list