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
a6ec1ce1
Kaydet (Commit)
a6ec1ce1
authored
May 31, 2019
tarafından
Ammar Askar
Kaydeden (comit)
Berker Peksag
May 31, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-33361: Fix bug with seeking in StreamRecoders (GH-8278)
üst
aac4d034
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
0 deletions
+33
-0
codecs.py
Lib/codecs.py
+6
-0
test_codecs.py
Lib/test/test_codecs.py
+25
-0
2018-07-13-20-17-17.bpo-33361.dx2NVn.rst
...S.d/next/Library/2018-07-13-20-17-17.bpo-33361.dx2NVn.rst
+2
-0
No files found.
Lib/codecs.py
Dosyayı görüntüle @
a6ec1ce1
...
...
@@ -847,6 +847,12 @@ class StreamRecoder:
self
.
reader
.
reset
()
self
.
writer
.
reset
()
def
seek
(
self
,
offset
,
whence
=
0
):
# Seeks must be propagated to both the readers and writers
# as they might need to reset their internal buffers.
self
.
reader
.
seek
(
offset
,
whence
)
self
.
writer
.
seek
(
offset
,
whence
)
def
__getattr__
(
self
,
name
,
getattr
=
getattr
):
...
...
Lib/test/test_codecs.py
Dosyayı görüntüle @
a6ec1ce1
...
...
@@ -3166,6 +3166,31 @@ class StreamRecoderTest(unittest.TestCase):
sr
.
write
(
text
.
encode
(
'latin1'
))
self
.
assertEqual
(
bio
.
getvalue
(),
text
.
encode
(
'utf-8'
))
def
test_seeking_read
(
self
):
bio
=
io
.
BytesIO
(
'line1
\n
line2
\n
line3
\n
'
.
encode
(
'utf-16-le'
))
sr
=
codecs
.
EncodedFile
(
bio
,
'utf-8'
,
'utf-16-le'
)
self
.
assertEqual
(
sr
.
readline
(),
b
'line1
\n
'
)
sr
.
seek
(
0
)
self
.
assertEqual
(
sr
.
readline
(),
b
'line1
\n
'
)
self
.
assertEqual
(
sr
.
readline
(),
b
'line2
\n
'
)
self
.
assertEqual
(
sr
.
readline
(),
b
'line3
\n
'
)
self
.
assertEqual
(
sr
.
readline
(),
b
''
)
def
test_seeking_write
(
self
):
bio
=
io
.
BytesIO
(
'123456789
\n
'
.
encode
(
'utf-16-le'
))
sr
=
codecs
.
EncodedFile
(
bio
,
'utf-8'
,
'utf-16-le'
)
# Test that seek() only resets its internal buffer when offset
# and whence are zero.
sr
.
seek
(
2
)
sr
.
write
(
b
'
\n
abc
\n
'
)
self
.
assertEqual
(
sr
.
readline
(),
b
'789
\n
'
)
sr
.
seek
(
0
)
self
.
assertEqual
(
sr
.
readline
(),
b
'1
\n
'
)
self
.
assertEqual
(
sr
.
readline
(),
b
'abc
\n
'
)
self
.
assertEqual
(
sr
.
readline
(),
b
'789
\n
'
)
@unittest.skipIf
(
_testcapi
is
None
,
'need _testcapi module'
)
class
LocaleCodecTest
(
unittest
.
TestCase
):
...
...
Misc/NEWS.d/next/Library/2018-07-13-20-17-17.bpo-33361.dx2NVn.rst
0 → 100644
Dosyayı görüntüle @
a6ec1ce1
Fix a bug in :class:`codecs.StreamRecoder` where seeking might leave old data in a
buffer and break subsequent read calls. Patch by Ammar Askar.
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