Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
be6dbfb4
Unverified
Kaydet (Commit)
be6dbfb4
authored
Nis 29, 2019
tarafından
Berker Peksag
Kaydeden (comit)
GitHub
Nis 29, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-1613500: Don't hardcode output file mode in fileinput.FileInput (GH-12986)
üst
88c09370
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
2 deletions
+16
-2
fileinput.py
Lib/fileinput.py
+3
-2
test_fileinput.py
Lib/test/test_fileinput.py
+10
-0
2019-04-27-21-09-33.bpo-1613500.Ogp4P0.rst
...d/next/Library/2019-04-27-21-09-33.bpo-1613500.Ogp4P0.rst
+3
-0
No files found.
Lib/fileinput.py
Dosyayı görüntüle @
be6dbfb4
...
...
@@ -222,6 +222,7 @@ class FileInput:
warnings
.
warn
(
"'U' mode is deprecated"
,
DeprecationWarning
,
2
)
self
.
_mode
=
mode
self
.
_write_mode
=
mode
.
replace
(
'r'
,
'w'
)
if
'U'
not
in
mode
else
'w'
if
openhook
:
if
inplace
:
raise
ValueError
(
"FileInput cannot use an opening hook in inplace mode"
)
...
...
@@ -348,14 +349,14 @@ class FileInput:
try
:
perm
=
os
.
fstat
(
self
.
_file
.
fileno
())
.
st_mode
except
OSError
:
self
.
_output
=
open
(
self
.
_filename
,
"w"
)
self
.
_output
=
open
(
self
.
_filename
,
self
.
_write_mode
)
else
:
mode
=
os
.
O_CREAT
|
os
.
O_WRONLY
|
os
.
O_TRUNC
if
hasattr
(
os
,
'O_BINARY'
):
mode
|=
os
.
O_BINARY
fd
=
os
.
open
(
self
.
_filename
,
mode
,
perm
)
self
.
_output
=
os
.
fdopen
(
fd
,
"w"
)
self
.
_output
=
os
.
fdopen
(
fd
,
self
.
_write_mode
)
try
:
os
.
chmod
(
self
.
_filename
,
perm
)
except
OSError
:
...
...
Lib/test/test_fileinput.py
Dosyayı görüntüle @
be6dbfb4
...
...
@@ -329,6 +329,16 @@ class FileInputTests(BaseTests, unittest.TestCase):
self
.
assertEqual
(
fi
.
readline
(),
b
''
)
self
.
assertEqual
(
fi
.
readline
(),
b
''
)
def
test_inplace_binary_write_mode
(
self
):
temp_file
=
self
.
writeTmp
(
b
'Initial text.'
,
mode
=
'wb'
)
with
FileInput
(
temp_file
,
mode
=
'rb'
,
inplace
=
True
)
as
fobj
:
line
=
fobj
.
readline
()
self
.
assertEqual
(
line
,
b
'Initial text.'
)
# print() cannot be used with files opened in binary mode.
sys
.
stdout
.
write
(
b
'New line.'
)
with
open
(
temp_file
,
'rb'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
b
'New line.'
)
def
test_context_manager
(
self
):
t1
=
self
.
writeTmp
(
"A
\n
B
\n
C"
)
t2
=
self
.
writeTmp
(
"D
\n
E
\n
F"
)
...
...
Misc/NEWS.d/next/Library/2019-04-27-21-09-33.bpo-1613500.Ogp4P0.rst
0 → 100644
Dosyayı görüntüle @
be6dbfb4
:class:`fileinput.FileInput` now uses the input file mode to correctly set
the output file mode (previously it was hardcoded to ``'w'``) when
``inplace=True`` is passed to its constructor.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment