Add newline arg to open().
This commit is contained in:
parent
4109356d29
commit
9cbb5f0731
14
pep-3116.txt
14
pep-3116.txt
|
@ -413,11 +413,13 @@ The ``open()`` Built-in Function
|
||||||
The ``open()`` built-in function is specified by the following
|
The ``open()`` built-in function is specified by the following
|
||||||
pseudo-code::
|
pseudo-code::
|
||||||
|
|
||||||
def open(filename, mode="r", buffering=None, *, encoding=None):
|
def open(filename, mode="r", buffering=None, *,
|
||||||
assert isinstance(filename, str)
|
encoding=None, newline=None):
|
||||||
|
assert isinstance(filename, (str, int))
|
||||||
assert isinstance(mode, str)
|
assert isinstance(mode, str)
|
||||||
assert buffering is None or isinstance(buffering, int)
|
assert buffering is None or isinstance(buffering, int)
|
||||||
assert encoding is None or isinstance(encoding, str)
|
assert encoding is None or isinstance(encoding, str)
|
||||||
|
assert newline in (None, "\n", "\r\n")
|
||||||
modes = set(mode)
|
modes = set(mode)
|
||||||
if modes - set("arwb+t") or len(mode) > len(modes):
|
if modes - set("arwb+t") or len(mode) > len(modes):
|
||||||
raise ValueError("invalid mode: %r" % mode)
|
raise ValueError("invalid mode: %r" % mode)
|
||||||
|
@ -434,7 +436,9 @@ pseudo-code::
|
||||||
if not (reading or writing or appending):
|
if not (reading or writing or appending):
|
||||||
raise ValueError("must have exactly one of read/write/append mode")
|
raise ValueError("must have exactly one of read/write/append mode")
|
||||||
if binary and encoding is not None:
|
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()
|
# XXX Need to spec the signature for FileIO()
|
||||||
raw = FileIO(filename, mode)
|
raw = FileIO(filename, mode)
|
||||||
if buffering is None:
|
if buffering is None:
|
||||||
|
@ -456,9 +460,7 @@ pseudo-code::
|
||||||
if binary:
|
if binary:
|
||||||
return buffer
|
return buffer
|
||||||
assert text
|
assert text
|
||||||
# XXX Need to do something about universal newlines?
|
return TextIOWrapper(buffer, encoding, newline)
|
||||||
textio = TextIOWrapper(buffer)
|
|
||||||
return textio
|
|
||||||
|
|
||||||
|
|
||||||
Copyright
|
Copyright
|
||||||
|
|
Loading…
Reference in New Issue