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
a9f054b4
Kaydet (Commit)
a9f054b4
authored
Kas 23, 2010
tarafından
Łukasz Langa
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
zipfile: remove remaining ResourceWarnings
üst
e94980a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
16 deletions
+24
-16
test_zipfile.py
Lib/test/test_zipfile.py
+10
-11
zipfile.py
Lib/zipfile.py
+14
-5
No files found.
Lib/test/test_zipfile.py
Dosyayı görüntüle @
a9f054b4
...
...
@@ -609,7 +609,7 @@ class TestZip64InSmallFiles(unittest.TestCase):
class
PyZipFileTests
(
unittest
.
TestCase
):
def
test_write_pyfile
(
self
):
with
zipfile
.
PyZipFile
(
TemporaryFile
()
,
"w"
)
as
zipfp
:
with
TemporaryFile
()
as
t
,
zipfile
.
PyZipFile
(
t
,
"w"
)
as
zipfp
:
fn
=
__file__
if
fn
.
endswith
(
'.pyc'
)
or
fn
.
endswith
(
'.pyo'
):
path_split
=
fn
.
split
(
os
.
sep
)
...
...
@@ -627,7 +627,7 @@ class PyZipFileTests(unittest.TestCase):
self
.
assertTrue
(
bn
+
'o'
in
zipfp
.
namelist
()
or
bn
+
'c'
in
zipfp
.
namelist
())
with
zipfile
.
PyZipFile
(
TemporaryFile
()
,
"w"
)
as
zipfp
:
with
TemporaryFile
()
as
t
,
zipfile
.
PyZipFile
(
t
,
"w"
)
as
zipfp
:
fn
=
__file__
if
fn
.
endswith
((
'.pyc'
,
'.pyo'
)):
fn
=
fn
[:
-
1
]
...
...
@@ -643,7 +643,7 @@ class PyZipFileTests(unittest.TestCase):
import
email
packagedir
=
os
.
path
.
dirname
(
email
.
__file__
)
with
zipfile
.
PyZipFile
(
TemporaryFile
()
,
"w"
)
as
zipfp
:
with
TemporaryFile
()
as
t
,
zipfile
.
PyZipFile
(
t
,
"w"
)
as
zipfp
:
zipfp
.
writepy
(
packagedir
)
# Check for a couple of modules at different levels of the
...
...
@@ -666,26 +666,25 @@ class PyZipFileTests(unittest.TestCase):
with
open
(
os
.
path
.
join
(
TESTFN2
,
"mod2.txt"
),
"w"
)
as
fp
:
fp
.
write
(
"bla bla bla
\n
"
)
zipfp
=
zipfile
.
PyZipFile
(
TemporaryFile
(),
"w"
)
zipfp
.
writepy
(
TESTFN2
)
with
TemporaryFile
()
as
t
,
zipfile
.
PyZipFile
(
t
,
"w"
)
as
zipfp
:
zipfp
.
writepy
(
TESTFN2
)
names
=
zipfp
.
namelist
()
self
.
assertTrue
(
'mod1.pyc'
in
names
or
'mod1.pyo'
in
names
)
self
.
assertTrue
(
'mod2.pyc'
in
names
or
'mod2.pyo'
in
names
)
self
.
assertNotIn
(
'mod2.txt'
,
names
)
names
=
zipfp
.
namelist
()
self
.
assertTrue
(
'mod1.pyc'
in
names
or
'mod1.pyo'
in
names
)
self
.
assertTrue
(
'mod2.pyc'
in
names
or
'mod2.pyo'
in
names
)
self
.
assertNotIn
(
'mod2.txt'
,
names
)
finally
:
shutil
.
rmtree
(
TESTFN2
)
def
test_write_non_pyfile
(
self
):
with
zipfile
.
PyZipFile
(
TemporaryFile
()
,
"w"
)
as
zipfp
:
with
TemporaryFile
()
as
t
,
zipfile
.
PyZipFile
(
t
,
"w"
)
as
zipfp
:
with
open
(
TESTFN
,
'w'
)
as
f
:
f
.
write
(
'most definitely not a python file'
)
self
.
assertRaises
(
RuntimeError
,
zipfp
.
writepy
,
TESTFN
)
os
.
remove
(
TESTFN
)
class
OtherTests
(
unittest
.
TestCase
):
zips_with_bad_crc
=
{
zipfile
.
ZIP_STORED
:
(
...
...
Lib/zipfile.py
Dosyayı görüntüle @
a9f054b4
...
...
@@ -897,10 +897,8 @@ class ZipFile:
# given a file object in the constructor
if
self
.
_filePassed
:
zef_file
=
self
.
fp
should_close
=
False
else
:
zef_file
=
io
.
open
(
self
.
filename
,
'rb'
)
should_close
=
True
# Make sure we have an info object
if
isinstance
(
name
,
ZipInfo
):
...
...
@@ -908,8 +906,12 @@ class ZipFile:
zinfo
=
name
else
:
# Get info object for name
zinfo
=
self
.
getinfo
(
name
)
try
:
zinfo
=
self
.
getinfo
(
name
)
except
KeyError
:
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
zef_file
.
seek
(
zinfo
.
header_offset
,
0
)
# Skip the file header:
...
...
@@ -923,6 +925,8 @@ class ZipFile:
zef_file
.
read
(
fheader
[
_FH_EXTRA_FIELD_LENGTH
])
if
fname
!=
zinfo
.
orig_filename
.
encode
(
"utf-8"
):
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
BadZipFile
(
'File name in directory
%
r and header
%
r differ.'
%
(
zinfo
.
orig_filename
,
fname
))
...
...
@@ -934,6 +938,8 @@ class ZipFile:
if
not
pwd
:
pwd
=
self
.
pwd
if
not
pwd
:
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
RuntimeError
(
"File
%
s is encrypted, "
"password required for extraction"
%
name
)
...
...
@@ -952,9 +958,12 @@ class ZipFile:
# compare against the CRC otherwise
check_byte
=
(
zinfo
.
CRC
>>
24
)
&
0xff
if
h
[
11
]
!=
check_byte
:
if
not
self
.
_filePassed
:
zef_file
.
close
()
raise
RuntimeError
(
"Bad password for file"
,
name
)
return
ZipExtFile
(
zef_file
,
mode
,
zinfo
,
zd
,
close_fileobj
=
should_close
)
return
ZipExtFile
(
zef_file
,
mode
,
zinfo
,
zd
,
close_fileobj
=
not
self
.
_filePassed
)
def
extract
(
self
,
member
,
path
=
None
,
pwd
=
None
):
"""Extract a member from the archive to the current working directory,
...
...
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