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
68b8a94c
Kaydet (Commit)
68b8a94c
authored
Şub 26, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20501: fileinput module no longer reads whole file into memory when using
fileinput.hook_encoded.
üst
17a4322d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
3 deletions
+48
-3
fileinput.py
Lib/fileinput.py
+3
-2
test_fileinput.py
Lib/test/test_fileinput.py
+42
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/fileinput.py
Dosyayı görüntüle @
68b8a94c
...
@@ -387,9 +387,10 @@ def hook_compressed(filename, mode):
...
@@ -387,9 +387,10 @@ def hook_compressed(filename, mode):
def
hook_encoded
(
encoding
):
def
hook_encoded
(
encoding
):
import
codecs
import
io
def
openhook
(
filename
,
mode
):
def
openhook
(
filename
,
mode
):
return
codecs
.
open
(
filename
,
mode
,
encoding
)
mode
=
mode
.
replace
(
'U'
,
''
)
.
replace
(
'b'
,
''
)
or
'r'
return
io
.
open
(
filename
,
mode
,
encoding
=
encoding
,
newline
=
''
)
return
openhook
return
openhook
...
...
Lib/test/test_fileinput.py
Dosyayı görüntüle @
68b8a94c
...
@@ -218,8 +218,49 @@ class FileInputTests(unittest.TestCase):
...
@@ -218,8 +218,49 @@ class FileInputTests(unittest.TestCase):
finally
:
finally
:
remove_tempfiles
(
t1
)
remove_tempfiles
(
t1
)
def
test_readline
(
self
):
with
open
(
TESTFN
,
'wb'
)
as
f
:
f
.
write
(
'A
\n
B
\r\n
C
\r
'
)
# Fill TextIOWrapper buffer.
f
.
write
(
'123456789
\n
'
*
1000
)
# Issue #20501: readline() shouldn't read whole file.
f
.
write
(
'
\x80
'
)
self
.
addCleanup
(
safe_unlink
,
TESTFN
)
fi
=
FileInput
(
files
=
TESTFN
,
openhook
=
hook_encoded
(
'ascii'
),
bufsize
=
8
)
self
.
assertEqual
(
fi
.
readline
(),
u'A
\n
'
)
self
.
assertEqual
(
fi
.
readline
(),
u'B
\r\n
'
)
self
.
assertEqual
(
fi
.
readline
(),
u'C
\r
'
)
with
self
.
assertRaises
(
UnicodeDecodeError
):
# Read to the end of file.
list
(
fi
)
fi
.
close
()
class
Test_hook_encoded
(
unittest
.
TestCase
):
"""Unit tests for fileinput.hook_encoded()"""
def
test_modes
(
self
):
# Unlikely UTF-7 is locale encoding
with
open
(
TESTFN
,
'wb'
)
as
f
:
f
.
write
(
'A
\n
B
\r\n
C
\r
D+IKw-'
)
t1
=
TESTFN
#t1 = writeTmp(1, ['A\nB\r\nC\rD+IKw-'], mode='wb')
self
.
addCleanup
(
safe_unlink
,
TESTFN
)
def
check
(
mode
,
expected_lines
):
fi
=
FileInput
(
files
=
TESTFN
,
mode
=
mode
,
openhook
=
hook_encoded
(
'utf-7'
))
lines
=
list
(
fi
)
fi
.
close
()
self
.
assertEqual
(
lines
,
expected_lines
)
check
(
'r'
,
[
u'A
\n
'
,
u'B
\r\n
'
,
u'C
\r
'
,
u'D
\u20ac
'
])
check
(
'rU'
,
[
u'A
\n
'
,
u'B
\r\n
'
,
u'C
\r
'
,
u'D
\u20ac
'
])
check
(
'U'
,
[
u'A
\n
'
,
u'B
\r\n
'
,
u'C
\r
'
,
u'D
\u20ac
'
])
check
(
'rb'
,
[
u'A
\n
'
,
u'B
\r\n
'
,
u'C
\r
'
,
u'D
\u20ac
'
])
def
test_main
():
def
test_main
():
run_unittest
(
BufferSizesTests
,
FileInputTests
)
run_unittest
(
BufferSizesTests
,
FileInputTests
,
Test_hook_encoded
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
test_main
()
Misc/NEWS
Dosyayı görüntüle @
68b8a94c
...
@@ -40,6 +40,9 @@ Core and Builtins
...
@@ -40,6 +40,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
20501
:
fileinput
module
no
longer
reads
whole
file
into
memory
when
using
fileinput
.
hook_encoded
.
-
Issue
#
6815
:
os
.
path
.
expandvars
()
now
supports
non
-
ASCII
Unicode
environment
-
Issue
#
6815
:
os
.
path
.
expandvars
()
now
supports
non
-
ASCII
Unicode
environment
variables
names
and
values
.
variables
names
and
values
.
...
...
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