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
d4c2ac83
Kaydet (Commit)
d4c2ac83
authored
Mar 23, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #21560: An attempt to write a data of wrong type no longer cause
GzipFile corruption. Original patch by Wolfgang Maier.
üst
f6e31b79
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
2 deletions
+38
-2
gzip.py
Lib/gzip.py
+2
-2
test_gzip.py
Lib/test/test_gzip.py
+33
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/gzip.py
Dosyayı görüntüle @
d4c2ac83
...
...
@@ -339,9 +339,9 @@ class GzipFile(io.BufferedIOBase):
data
=
data
.
tobytes
()
if
len
(
data
)
>
0
:
self
.
size
=
self
.
size
+
len
(
data
)
self
.
fileobj
.
write
(
self
.
compress
.
compress
(
data
))
self
.
size
+=
len
(
data
)
self
.
crc
=
zlib
.
crc32
(
data
,
self
.
crc
)
&
0xffffffff
self
.
fileobj
.
write
(
self
.
compress
.
compress
(
data
)
)
self
.
offset
+=
len
(
data
)
return
len
(
data
)
...
...
Lib/test/test_gzip.py
Dosyayı görüntüle @
d4c2ac83
...
...
@@ -43,6 +43,14 @@ class BaseTest(unittest.TestCase):
class
TestGzip
(
BaseTest
):
def
write_and_read_back
(
self
,
data
,
mode
=
'b'
):
b_data
=
bytes
(
data
)
with
gzip
.
GzipFile
(
self
.
filename
,
'w'
+
mode
)
as
f
:
l
=
f
.
write
(
data
)
self
.
assertEqual
(
l
,
len
(
b_data
))
with
gzip
.
GzipFile
(
self
.
filename
,
'r'
+
mode
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
b_data
)
def
test_write
(
self
):
with
gzip
.
GzipFile
(
self
.
filename
,
'wb'
)
as
f
:
f
.
write
(
data1
*
50
)
...
...
@@ -57,6 +65,31 @@ class TestGzip(BaseTest):
# Test multiple close() calls.
f
.
close
()
# The following test_write_xy methods test that write accepts
# the corresponding bytes-like object type as input
# and that the data written equals bytes(xy) in all cases.
def
test_write_memoryview
(
self
):
self
.
write_and_read_back
(
memoryview
(
data1
*
50
))
m
=
memoryview
(
bytes
(
range
(
256
)))
data
=
m
.
cast
(
'B'
,
shape
=
[
8
,
8
,
4
])
self
.
write_and_read_back
(
data
)
def
test_write_bytearray
(
self
):
self
.
write_and_read_back
(
bytearray
(
data1
*
50
))
def
test_write_incompatible_type
(
self
):
# Test that non-bytes-like types raise TypeError.
# Issue #21560: attempts to write incompatible types
# should not affect the state of the fileobject
with
gzip
.
GzipFile
(
self
.
filename
,
'wb'
)
as
f
:
with
self
.
assertRaises
(
TypeError
):
f
.
write
(
'a'
)
with
self
.
assertRaises
(
TypeError
):
f
.
write
([
1
])
f
.
write
(
data1
)
with
gzip
.
GzipFile
(
self
.
filename
,
'rb'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
data1
)
def
test_read
(
self
):
self
.
test_write
()
# Try reading.
...
...
Misc/NEWS
Dosyayı görüntüle @
d4c2ac83
...
...
@@ -18,6 +18,9 @@ Core and Builtins
Library
-------
- Issue #21560: An attempt to write a data of wrong type no longer cause
GzipFile corruption. Original patch by Wolfgang Maier.
- Issue #23647: Increase impalib'
s
MAXLINE
to
accommodate
modern
mailbox
sizes
.
-
Issue
#
23539
:
If
body
is
None
,
http
.
client
.
HTTPConnection
.
request
now
sets
...
...
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