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
7980eaa9
Kaydet (Commit)
7980eaa9
authored
Eki 06, 2010
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #9759: GzipFile now raises ValueError when an operation is attempted
after the file is closed. Patch by Jeffrey Finkelstein.
üst
cd889af9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
0 deletions
+35
-0
gzip.py
Lib/gzip.py
+10
-0
test_gzip.py
Lib/test/test_gzip.py
+22
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/gzip.py
Dosyayı görüntüle @
7980eaa9
...
@@ -210,6 +210,13 @@ class GzipFile(io.BufferedIOBase):
...
@@ -210,6 +210,13 @@ class GzipFile(io.BufferedIOBase):
s
=
repr
(
fileobj
)
s
=
repr
(
fileobj
)
return
'<gzip '
+
s
[
1
:
-
1
]
+
' '
+
hex
(
id
(
self
))
+
'>'
return
'<gzip '
+
s
[
1
:
-
1
]
+
' '
+
hex
(
id
(
self
))
+
'>'
def
_check_closed
(
self
):
"""Raises a ValueError if the underlying file object has been closed.
"""
if
self
.
closed
:
raise
ValueError
(
'I/O operation on closed file.'
)
def
_init_write
(
self
,
filename
):
def
_init_write
(
self
,
filename
):
self
.
name
=
filename
self
.
name
=
filename
self
.
crc
=
zlib
.
crc32
(
b
""
)
&
0xffffffff
self
.
crc
=
zlib
.
crc32
(
b
""
)
&
0xffffffff
...
@@ -288,6 +295,7 @@ class GzipFile(io.BufferedIOBase):
...
@@ -288,6 +295,7 @@ class GzipFile(io.BufferedIOBase):
self
.
_add_read_data
(
uncompress
)
self
.
_add_read_data
(
uncompress
)
def
write
(
self
,
data
):
def
write
(
self
,
data
):
self
.
_check_closed
()
if
self
.
mode
!=
WRITE
:
if
self
.
mode
!=
WRITE
:
import
errno
import
errno
raise
IOError
(
errno
.
EBADF
,
"write() on read-only GzipFile object"
)
raise
IOError
(
errno
.
EBADF
,
"write() on read-only GzipFile object"
)
...
@@ -308,6 +316,7 @@ class GzipFile(io.BufferedIOBase):
...
@@ -308,6 +316,7 @@ class GzipFile(io.BufferedIOBase):
return
len
(
data
)
return
len
(
data
)
def
read
(
self
,
size
=-
1
):
def
read
(
self
,
size
=-
1
):
self
.
_check_closed
()
if
self
.
mode
!=
READ
:
if
self
.
mode
!=
READ
:
import
errno
import
errno
raise
IOError
(
errno
.
EBADF
,
"read() on write-only GzipFile object"
)
raise
IOError
(
errno
.
EBADF
,
"read() on write-only GzipFile object"
)
...
@@ -457,6 +466,7 @@ class GzipFile(io.BufferedIOBase):
...
@@ -457,6 +466,7 @@ class GzipFile(io.BufferedIOBase):
self
.
myfileobj
=
None
self
.
myfileobj
=
None
def
flush
(
self
,
zlib_mode
=
zlib
.
Z_SYNC_FLUSH
):
def
flush
(
self
,
zlib_mode
=
zlib
.
Z_SYNC_FLUSH
):
self
.
_check_closed
()
if
self
.
mode
==
WRITE
:
if
self
.
mode
==
WRITE
:
# Ensure the compressor's buffer is flushed
# Ensure the compressor's buffer is flushed
self
.
fileobj
.
write
(
self
.
compress
.
flush
(
zlib_mode
))
self
.
fileobj
.
write
(
self
.
compress
.
flush
(
zlib_mode
))
...
...
Lib/test/test_gzip.py
Dosyayı görüntüle @
7980eaa9
...
@@ -62,6 +62,28 @@ class TestGzip(unittest.TestCase):
...
@@ -62,6 +62,28 @@ class TestGzip(unittest.TestCase):
f
=
gzip
.
GzipFile
(
self
.
filename
,
'r'
)
;
d
=
f
.
read
()
;
f
.
close
()
f
=
gzip
.
GzipFile
(
self
.
filename
,
'r'
)
;
d
=
f
.
read
()
;
f
.
close
()
self
.
assertEqual
(
d
,
data1
*
50
)
self
.
assertEqual
(
d
,
data1
*
50
)
def
test_io_on_closed_object
(
self
):
# Test that I/O operations on closed GzipFile objects raise a
# ValueError, just like the corresponding functions on file objects.
# Write to a file, open it for reading, then close it.
self
.
test_write
()
f
=
gzip
.
GzipFile
(
self
.
filename
,
'r'
)
f
.
close
()
with
self
.
assertRaises
(
ValueError
):
f
.
read
(
1
)
with
self
.
assertRaises
(
ValueError
):
f
.
seek
(
0
)
with
self
.
assertRaises
(
ValueError
):
f
.
tell
()
# Open the file for writing, then close it.
f
=
gzip
.
GzipFile
(
self
.
filename
,
'w'
)
f
.
close
()
with
self
.
assertRaises
(
ValueError
):
f
.
write
(
b
''
)
with
self
.
assertRaises
(
ValueError
):
f
.
flush
()
def
test_append
(
self
):
def
test_append
(
self
):
self
.
test_write
()
self
.
test_write
()
# Append to the previous file
# Append to the previous file
...
...
Misc/NEWS
Dosyayı görüntüle @
7980eaa9
...
@@ -88,6 +88,9 @@ Core and Builtins
...
@@ -88,6 +88,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #9759: GzipFile now raises ValueError when an operation is attempted
after the file is closed. Patch by Jeffrey Finkelstein.
- Issue #9042: Fix interaction of custom translation classes and caching in
- Issue #9042: Fix interaction of custom translation classes and caching in
gettext.
gettext.
...
...
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