[Python-checkins] r54743 - peps/trunk/pep-3116.txt

guido.van.rossum python-checkins at python.org
Wed Apr 11 03:09:34 CEST 2007


Author: guido.van.rossum
Date: Wed Apr 11 03:09:33 2007
New Revision: 54743

Modified:
   peps/trunk/pep-3116.txt
Log:
Add newline arg to open().


Modified: peps/trunk/pep-3116.txt
==============================================================================
--- peps/trunk/pep-3116.txt	(original)
+++ peps/trunk/pep-3116.txt	Wed Apr 11 03:09:33 2007
@@ -413,11 +413,13 @@
 The ``open()`` built-in function is specified by the following
 pseudo-code::
 
-    def open(filename, mode="r", buffering=None, *, encoding=None):
-        assert isinstance(filename, str)
+    def open(filename, mode="r", buffering=None, *, 
+             encoding=None, newline=None):
+        assert isinstance(filename, (str, int))
         assert isinstance(mode, str)
         assert buffering is None or isinstance(buffering, int)
         assert encoding is None or isinstance(encoding, str)
+        assert newline in (None, "\n", "\r\n")
         modes = set(mode)
         if modes - set("arwb+t") or len(mode) > len(modes):
             raise ValueError("invalid mode: %r" % mode)
@@ -434,7 +436,9 @@
         if not (reading or writing or appending):
             raise ValueError("must have exactly one of read/write/append mode")
         if binary and encoding is not None:
-            raise ValueError("binary modes doesn't take an encoding")
+            raise ValueError("binary modes doesn't take an encoding arg")
+        if binary and newline is not None:
+            raise ValueError("binary modes doesn't take a newline arg")
         # XXX Need to spec the signature for FileIO()
         raw = FileIO(filename, mode)
         if buffering is None:
@@ -456,9 +460,7 @@
         if binary:
             return buffer
         assert text
-        # XXX Need to do something about universal newlines?
-        textio = TextIOWrapper(buffer)
-        return textio
+        return TextIOWrapper(buffer, encoding, newline)
 
 
 Copyright


More information about the Python-checkins mailing list