mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-69528: Distinguish between file modes "wb+" and "rb+" (GH-137834)
Co-authored-by: Xiang Zhang <angwerzx@126.com>
This commit is contained in:
parent
60df1d7e0c
commit
02c1abfc54
7 changed files with 27 additions and 10 deletions
|
|
@ -1498,6 +1498,7 @@ class FileIO(RawIOBase):
|
|||
_writable = False
|
||||
_appending = False
|
||||
_seekable = None
|
||||
_truncate = False
|
||||
_closefd = True
|
||||
|
||||
def __init__(self, file, mode='r', closefd=True, opener=None):
|
||||
|
|
@ -1553,6 +1554,7 @@ def __init__(self, file, mode='r', closefd=True, opener=None):
|
|||
flags = 0
|
||||
elif 'w' in mode:
|
||||
self._writable = True
|
||||
self._truncate = True
|
||||
flags = os.O_CREAT | os.O_TRUNC
|
||||
elif 'a' in mode:
|
||||
self._writable = True
|
||||
|
|
@ -1877,7 +1879,10 @@ def mode(self):
|
|||
return 'ab'
|
||||
elif self._readable:
|
||||
if self._writable:
|
||||
return 'rb+'
|
||||
if self._truncate:
|
||||
return 'wb+'
|
||||
else:
|
||||
return 'rb+'
|
||||
else:
|
||||
return 'rb'
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue