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
4d540885
Kaydet (Commit)
4d540885
authored
Eki 28, 2010
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#7351: add more consistent exception name alias.
üst
b156a46b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
26 deletions
+38
-26
zipfile.rst
Doc/library/zipfile.rst
+9
-1
test_zipfile.py
Lib/test/test_zipfile.py
+11
-11
zipfile.py
Lib/zipfile.py
+15
-14
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/zipfile.rst
Dosyayı görüntüle @
4d540885
...
@@ -24,10 +24,18 @@ For other archive formats, see the :mod:`bz2`, :mod:`gzip`, and
...
@@ -24,10 +24,18 @@ For other archive formats, see the :mod:`bz2`, :mod:`gzip`, and
The module defines the following items:
The module defines the following items:
.. exception:: BadZip
f
ile
.. exception:: BadZip
F
ile
The error raised for bad ZIP files (old name: ``zipfile.error``).
The error raised for bad ZIP files (old name: ``zipfile.error``).
.. versionadded:: 3.2
.. exception:: BadZipfile
This is an alias for :exc:`BadZipFile` that exists for compatibility with
Python versions prior to 3.2. Usage is deprecated.
.. exception:: LargeZipFile
.. exception:: LargeZipFile
...
...
Lib/test/test_zipfile.py
Dosyayı görüntüle @
4d540885
...
@@ -463,8 +463,8 @@ class TestsWithSourceFile(unittest.TestCase):
...
@@ -463,8 +463,8 @@ class TestsWithSourceFile(unittest.TestCase):
try
:
try
:
with
zipfile
.
ZipFile
(
TESTFN2
,
"r"
)
as
zipfp2
:
with
zipfile
.
ZipFile
(
TESTFN2
,
"r"
)
as
zipfp2
:
raise
zipfile
.
BadZip
f
ile
()
raise
zipfile
.
BadZip
F
ile
()
except
zipfile
.
BadZip
f
ile
:
except
zipfile
.
BadZip
F
ile
:
self
.
assertTrue
(
zipfp2
.
fp
is
None
,
'zipfp is not closed'
)
self
.
assertTrue
(
zipfp2
.
fp
is
None
,
'zipfp is not closed'
)
def
tearDown
(
self
):
def
tearDown
(
self
):
...
@@ -723,7 +723,7 @@ class OtherTests(unittest.TestCase):
...
@@ -723,7 +723,7 @@ class OtherTests(unittest.TestCase):
fp
.
write
(
"this is not a legal zip file
\n
"
)
fp
.
write
(
"this is not a legal zip file
\n
"
)
try
:
try
:
zf
=
zipfile
.
ZipFile
(
TESTFN
)
zf
=
zipfile
.
ZipFile
(
TESTFN
)
except
zipfile
.
BadZip
f
ile
:
except
zipfile
.
BadZip
F
ile
:
pass
pass
def
test_is_zip_erroneous_file
(
self
):
def
test_is_zip_erroneous_file
(
self
):
...
@@ -786,11 +786,11 @@ class OtherTests(unittest.TestCase):
...
@@ -786,11 +786,11 @@ class OtherTests(unittest.TestCase):
def
test_empty_file_raises_BadZipFile
(
self
):
def
test_empty_file_raises_BadZipFile
(
self
):
f
=
open
(
TESTFN
,
'w'
)
f
=
open
(
TESTFN
,
'w'
)
f
.
close
()
f
.
close
()
self
.
assertRaises
(
zipfile
.
BadZip
f
ile
,
zipfile
.
ZipFile
,
TESTFN
)
self
.
assertRaises
(
zipfile
.
BadZip
F
ile
,
zipfile
.
ZipFile
,
TESTFN
)
with
open
(
TESTFN
,
'w'
)
as
fp
:
with
open
(
TESTFN
,
'w'
)
as
fp
:
fp
.
write
(
"short file"
)
fp
.
write
(
"short file"
)
self
.
assertRaises
(
zipfile
.
BadZip
f
ile
,
zipfile
.
ZipFile
,
TESTFN
)
self
.
assertRaises
(
zipfile
.
BadZip
F
ile
,
zipfile
.
ZipFile
,
TESTFN
)
def
test_closed_zip_raises_RuntimeError
(
self
):
def
test_closed_zip_raises_RuntimeError
(
self
):
"""Verify that testzip() doesn't swallow inappropriate exceptions."""
"""Verify that testzip() doesn't swallow inappropriate exceptions."""
...
@@ -912,23 +912,23 @@ class OtherTests(unittest.TestCase):
...
@@ -912,23 +912,23 @@ class OtherTests(unittest.TestCase):
self
.
check_testzip_with_bad_crc
(
zipfile
.
ZIP_DEFLATED
)
self
.
check_testzip_with_bad_crc
(
zipfile
.
ZIP_DEFLATED
)
def
check_read_with_bad_crc
(
self
,
compression
):
def
check_read_with_bad_crc
(
self
,
compression
):
"""Tests that files with bad CRCs raise a BadZip
f
ile exception when read."""
"""Tests that files with bad CRCs raise a BadZip
F
ile exception when read."""
zipdata
=
self
.
zips_with_bad_crc
[
compression
]
zipdata
=
self
.
zips_with_bad_crc
[
compression
]
# Using ZipFile.read()
# Using ZipFile.read()
with
zipfile
.
ZipFile
(
io
.
BytesIO
(
zipdata
),
mode
=
"r"
)
as
zipf
:
with
zipfile
.
ZipFile
(
io
.
BytesIO
(
zipdata
),
mode
=
"r"
)
as
zipf
:
self
.
assertRaises
(
zipfile
.
BadZip
f
ile
,
zipf
.
read
,
'afile'
)
self
.
assertRaises
(
zipfile
.
BadZip
F
ile
,
zipf
.
read
,
'afile'
)
# Using ZipExtFile.read()
# Using ZipExtFile.read()
with
zipfile
.
ZipFile
(
io
.
BytesIO
(
zipdata
),
mode
=
"r"
)
as
zipf
:
with
zipfile
.
ZipFile
(
io
.
BytesIO
(
zipdata
),
mode
=
"r"
)
as
zipf
:
with
zipf
.
open
(
'afile'
,
'r'
)
as
corrupt_file
:
with
zipf
.
open
(
'afile'
,
'r'
)
as
corrupt_file
:
self
.
assertRaises
(
zipfile
.
BadZip
f
ile
,
corrupt_file
.
read
)
self
.
assertRaises
(
zipfile
.
BadZip
F
ile
,
corrupt_file
.
read
)
# Same with small reads (in order to exercise the buffering logic)
# Same with small reads (in order to exercise the buffering logic)
with
zipfile
.
ZipFile
(
io
.
BytesIO
(
zipdata
),
mode
=
"r"
)
as
zipf
:
with
zipfile
.
ZipFile
(
io
.
BytesIO
(
zipdata
),
mode
=
"r"
)
as
zipf
:
with
zipf
.
open
(
'afile'
,
'r'
)
as
corrupt_file
:
with
zipf
.
open
(
'afile'
,
'r'
)
as
corrupt_file
:
corrupt_file
.
MIN_READ_SIZE
=
2
corrupt_file
.
MIN_READ_SIZE
=
2
with
self
.
assertRaises
(
zipfile
.
BadZip
f
ile
):
with
self
.
assertRaises
(
zipfile
.
BadZip
F
ile
):
while
corrupt_file
.
read
(
2
):
while
corrupt_file
.
read
(
2
):
pass
pass
...
@@ -978,11 +978,11 @@ class OtherTests(unittest.TestCase):
...
@@ -978,11 +978,11 @@ class OtherTests(unittest.TestCase):
def
test_open_empty_file
(
self
):
def
test_open_empty_file
(
self
):
# Issue 1710703: Check that opening a file with less than 22 bytes
# Issue 1710703: Check that opening a file with less than 22 bytes
# raises a BadZip
f
ile exception (rather than the previously unhelpful
# raises a BadZip
F
ile exception (rather than the previously unhelpful
# IOError)
# IOError)
f
=
open
(
TESTFN
,
'w'
)
f
=
open
(
TESTFN
,
'w'
)
f
.
close
()
f
.
close
()
self
.
assertRaises
(
zipfile
.
BadZip
f
ile
,
zipfile
.
ZipFile
,
TESTFN
,
'r'
)
self
.
assertRaises
(
zipfile
.
BadZip
F
ile
,
zipfile
.
ZipFile
,
TESTFN
,
'r'
)
def
tearDown
(
self
):
def
tearDown
(
self
):
unlink
(
TESTFN
)
unlink
(
TESTFN
)
...
...
Lib/zipfile.py
Dosyayı görüntüle @
4d540885
...
@@ -22,10 +22,10 @@ except ImportError:
...
@@ -22,10 +22,10 @@ except ImportError:
zlib
=
None
zlib
=
None
crc32
=
binascii
.
crc32
crc32
=
binascii
.
crc32
__all__
=
[
"BadZip
file"
,
"error"
,
"ZIP_STORED"
,
"ZIP_DEFLATED"
,
"is_zipfile
"
,
__all__
=
[
"BadZip
File"
,
"BadZipfile"
,
"error"
,
"ZIP_STORED"
,
"ZIP_DEFLATED
"
,
"
ZipInfo"
,
"ZipFile"
,
"PyZipFile"
,
"LargeZipFile"
]
"
is_zipfile"
,
"ZipInfo"
,
"ZipFile"
,
"PyZipFile"
,
"LargeZipFile"
]
class
BadZip
f
ile
(
Exception
):
class
BadZip
F
ile
(
Exception
):
pass
pass
...
@@ -35,7 +35,8 @@ class LargeZipFile(Exception):
...
@@ -35,7 +35,8 @@ class LargeZipFile(Exception):
and those extensions are disabled.
and those extensions are disabled.
"""
"""
error
=
BadZipfile
# The exception raised by this module
error
=
BadZipfile
=
BadZipFile
# Pre-3.2 compatibility names
ZIP64_LIMIT
=
(
1
<<
31
)
-
1
ZIP64_LIMIT
=
(
1
<<
31
)
-
1
ZIP_FILECOUNT_LIMIT
=
1
<<
16
ZIP_FILECOUNT_LIMIT
=
1
<<
16
...
@@ -180,7 +181,7 @@ def _EndRecData64(fpin, offset, endrec):
...
@@ -180,7 +181,7 @@ def _EndRecData64(fpin, offset, endrec):
return
endrec
return
endrec
if
diskno
!=
0
or
disks
!=
1
:
if
diskno
!=
0
or
disks
!=
1
:
raise
BadZip
f
ile
(
"zipfiles that span multiple disks are not supported"
)
raise
BadZip
Z
ile
(
"zipfiles that span multiple disks are not supported"
)
# Assume no 'zip64 extensible data'
# Assume no 'zip64 extensible data'
fpin
.
seek
(
offset
-
sizeEndCentDir64Locator
-
sizeEndCentDir64
,
2
)
fpin
.
seek
(
offset
-
sizeEndCentDir64Locator
-
sizeEndCentDir64
,
2
)
...
@@ -592,7 +593,7 @@ class ZipExtFile(io.BufferedIOBase):
...
@@ -592,7 +593,7 @@ class ZipExtFile(io.BufferedIOBase):
self
.
_running_crc
=
crc32
(
newdata
,
self
.
_running_crc
)
&
0xffffffff
self
.
_running_crc
=
crc32
(
newdata
,
self
.
_running_crc
)
&
0xffffffff
# Check the CRC if we're at the end of the file
# Check the CRC if we're at the end of the file
if
eof
and
self
.
_running_crc
!=
self
.
_expected_crc
:
if
eof
and
self
.
_running_crc
!=
self
.
_expected_crc
:
raise
BadZip
f
ile
(
"Bad CRC-32 for file
%
r"
%
self
.
name
)
raise
BadZip
F
ile
(
"Bad CRC-32 for file
%
r"
%
self
.
name
)
def
read1
(
self
,
n
):
def
read1
(
self
,
n
):
"""Read up to n bytes with at most one read() system call."""
"""Read up to n bytes with at most one read() system call."""
...
@@ -720,7 +721,7 @@ class ZipFile:
...
@@ -720,7 +721,7 @@ class ZipFile:
self
.
_RealGetContents
()
self
.
_RealGetContents
()
# seek to start of directory and overwrite
# seek to start of directory and overwrite
self
.
fp
.
seek
(
self
.
start_dir
,
0
)
self
.
fp
.
seek
(
self
.
start_dir
,
0
)
except
BadZip
f
ile
:
except
BadZip
F
ile
:
# file is not a zip file, just append
# file is not a zip file, just append
self
.
fp
.
seek
(
0
,
2
)
self
.
fp
.
seek
(
0
,
2
)
...
@@ -744,7 +745,7 @@ class ZipFile:
...
@@ -744,7 +745,7 @@ class ZipFile:
is bad."""
is bad."""
try
:
try
:
self
.
_RealGetContents
()
self
.
_RealGetContents
()
except
BadZip
f
ile
:
except
BadZip
F
ile
:
if
not
self
.
_filePassed
:
if
not
self
.
_filePassed
:
self
.
fp
.
close
()
self
.
fp
.
close
()
self
.
fp
=
None
self
.
fp
=
None
...
@@ -756,9 +757,9 @@ class ZipFile:
...
@@ -756,9 +757,9 @@ class ZipFile:
try
:
try
:
endrec
=
_EndRecData
(
fp
)
endrec
=
_EndRecData
(
fp
)
except
IOError
:
except
IOError
:
raise
BadZip
f
ile
(
"File is not a zip file"
)
raise
BadZip
F
ile
(
"File is not a zip file"
)
if
not
endrec
:
if
not
endrec
:
raise
BadZip
f
ile
(
"File is not a zip file"
)
raise
BadZip
F
ile
(
"File is not a zip file"
)
if
self
.
debug
>
1
:
if
self
.
debug
>
1
:
print
(
endrec
)
print
(
endrec
)
size_cd
=
endrec
[
_ECD_SIZE
]
# bytes in central directory
size_cd
=
endrec
[
_ECD_SIZE
]
# bytes in central directory
...
@@ -783,7 +784,7 @@ class ZipFile:
...
@@ -783,7 +784,7 @@ class ZipFile:
while
total
<
size_cd
:
while
total
<
size_cd
:
centdir
=
fp
.
read
(
sizeCentralDir
)
centdir
=
fp
.
read
(
sizeCentralDir
)
if
centdir
[
0
:
4
]
!=
stringCentralDir
:
if
centdir
[
0
:
4
]
!=
stringCentralDir
:
raise
BadZip
f
ile
(
"Bad magic number for central directory"
)
raise
BadZip
F
ile
(
"Bad magic number for central directory"
)
centdir
=
struct
.
unpack
(
structCentralDir
,
centdir
)
centdir
=
struct
.
unpack
(
structCentralDir
,
centdir
)
if
self
.
debug
>
2
:
if
self
.
debug
>
2
:
print
(
centdir
)
print
(
centdir
)
...
@@ -854,7 +855,7 @@ class ZipFile:
...
@@ -854,7 +855,7 @@ class ZipFile:
f
=
self
.
open
(
zinfo
.
filename
,
"r"
)
f
=
self
.
open
(
zinfo
.
filename
,
"r"
)
while
f
.
read
(
chunk_size
):
# Check CRC-32
while
f
.
read
(
chunk_size
):
# Check CRC-32
pass
pass
except
BadZip
f
ile
:
except
BadZip
F
ile
:
return
zinfo
.
filename
return
zinfo
.
filename
def
getinfo
(
self
,
name
):
def
getinfo
(
self
,
name
):
...
@@ -903,7 +904,7 @@ class ZipFile:
...
@@ -903,7 +904,7 @@ class ZipFile:
# Skip the file header:
# Skip the file header:
fheader
=
zef_file
.
read
(
sizeFileHeader
)
fheader
=
zef_file
.
read
(
sizeFileHeader
)
if
fheader
[
0
:
4
]
!=
stringFileHeader
:
if
fheader
[
0
:
4
]
!=
stringFileHeader
:
raise
BadZip
f
ile
(
"Bad magic number for file header"
)
raise
BadZip
F
ile
(
"Bad magic number for file header"
)
fheader
=
struct
.
unpack
(
structFileHeader
,
fheader
)
fheader
=
struct
.
unpack
(
structFileHeader
,
fheader
)
fname
=
zef_file
.
read
(
fheader
[
_FH_FILENAME_LENGTH
])
fname
=
zef_file
.
read
(
fheader
[
_FH_FILENAME_LENGTH
])
...
@@ -911,7 +912,7 @@ class ZipFile:
...
@@ -911,7 +912,7 @@ class ZipFile:
zef_file
.
read
(
fheader
[
_FH_EXTRA_FIELD_LENGTH
])
zef_file
.
read
(
fheader
[
_FH_EXTRA_FIELD_LENGTH
])
if
fname
!=
zinfo
.
orig_filename
.
encode
(
"utf-8"
):
if
fname
!=
zinfo
.
orig_filename
.
encode
(
"utf-8"
):
raise
BadZip
f
ile
(
raise
BadZip
F
ile
(
'File name in directory
%
r and header
%
r differ.'
'File name in directory
%
r and header
%
r differ.'
%
(
zinfo
.
orig_filename
,
fname
))
%
(
zinfo
.
orig_filename
,
fname
))
...
...
Misc/NEWS
Dosyayı görüntüle @
4d540885
...
@@ -51,6 +51,9 @@ Core and Builtins
...
@@ -51,6 +51,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #7351: Add ``zipfile.BadZipFile`` spelling of the exception name
and deprecate the old name ``zipfile.BadZipfile``.
- Issue #5027: The standard ``xml`` namespace is now understood by
- Issue #5027: The standard ``xml`` namespace is now understood by
xml.sax.saxutils.XMLGenerator as being bound to
xml.sax.saxutils.XMLGenerator as being bound to
http://www.w3.org/XML/1998/namespace. Patch by Troy J. Farrell.
http://www.w3.org/XML/1998/namespace. Patch by Troy J. Farrell.
...
...
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