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
8c933105
Kaydet (Commit)
8c933105
authored
Eki 23, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28115: Command-line interface of the zipfile module now uses argparse.
Added support of long options.
üst
e4bdf4fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
67 deletions
+71
-67
test_zipfile.py
Lib/test/test_zipfile.py
+31
-27
zipfile.py
Lib/zipfile.py
+37
-40
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_zipfile.py
Dosyayı görüntüle @
8c933105
...
...
@@ -2055,8 +2055,9 @@ class CommandLineTest(unittest.TestCase):
def
test_test_command
(
self
):
zip_name
=
findfile
(
'zipdir.zip'
)
out
=
self
.
zipfilecmd
(
'-t'
,
zip_name
)
self
.
assertEqual
(
out
.
rstrip
(),
b
'Done testing'
)
for
opt
in
'-t'
,
'--test'
:
out
=
self
.
zipfilecmd
(
opt
,
zip_name
)
self
.
assertEqual
(
out
.
rstrip
(),
b
'Done testing'
)
zip_name
=
findfile
(
'testtar.tar'
)
rc
,
out
,
err
=
self
.
zipfilecmd_failure
(
'-t'
,
zip_name
)
self
.
assertEqual
(
out
,
b
''
)
...
...
@@ -2067,9 +2068,10 @@ class CommandLineTest(unittest.TestCase):
with
zipfile
.
ZipFile
(
zip_name
,
'r'
)
as
tf
:
tf
.
printdir
(
t
)
expected
=
t
.
getvalue
()
.
encode
(
'ascii'
,
'backslashreplace'
)
out
=
self
.
zipfilecmd
(
'-l'
,
zip_name
,
PYTHONIOENCODING
=
'ascii:backslashreplace'
)
self
.
assertEqual
(
out
,
expected
)
for
opt
in
'-l'
,
'--list'
:
out
=
self
.
zipfilecmd
(
opt
,
zip_name
,
PYTHONIOENCODING
=
'ascii:backslashreplace'
)
self
.
assertEqual
(
out
,
expected
)
def
test_create_command
(
self
):
self
.
addCleanup
(
unlink
,
TESTFN
)
...
...
@@ -2081,31 +2083,33 @@ class CommandLineTest(unittest.TestCase):
f
.
write
(
'test 2'
)
files
=
[
TESTFN
,
TESTFNDIR
]
namelist
=
[
TESTFN
,
TESTFNDIR
+
'/'
,
TESTFNDIR
+
'/file.txt'
]
try
:
out
=
self
.
zipfilecmd
(
'-c'
,
TESTFN2
,
*
files
)
self
.
assertEqual
(
out
,
b
''
)
with
zipfile
.
ZipFile
(
TESTFN2
)
as
zf
:
self
.
assertEqual
(
zf
.
namelist
(),
namelist
)
self
.
assertEqual
(
zf
.
read
(
namelist
[
0
]),
b
'test 1'
)
self
.
assertEqual
(
zf
.
read
(
namelist
[
2
]),
b
'test 2'
)
finally
:
unlink
(
TESTFN2
)
for
opt
in
'-c'
,
'--create'
:
try
:
out
=
self
.
zipfilecmd
(
opt
,
TESTFN2
,
*
files
)
self
.
assertEqual
(
out
,
b
''
)
with
zipfile
.
ZipFile
(
TESTFN2
)
as
zf
:
self
.
assertEqual
(
zf
.
namelist
(),
namelist
)
self
.
assertEqual
(
zf
.
read
(
namelist
[
0
]),
b
'test 1'
)
self
.
assertEqual
(
zf
.
read
(
namelist
[
2
]),
b
'test 2'
)
finally
:
unlink
(
TESTFN2
)
def
test_extract_command
(
self
):
zip_name
=
findfile
(
'zipdir.zip'
)
with
temp_dir
()
as
extdir
:
out
=
self
.
zipfilecmd
(
'-e'
,
zip_name
,
extdir
)
self
.
assertEqual
(
out
,
b
''
)
with
zipfile
.
ZipFile
(
zip_name
)
as
zf
:
for
zi
in
zf
.
infolist
():
path
=
os
.
path
.
join
(
extdir
,
zi
.
filename
.
replace
(
'/'
,
os
.
sep
))
if
zi
.
is_dir
():
self
.
assertTrue
(
os
.
path
.
isdir
(
path
))
else
:
self
.
assertTrue
(
os
.
path
.
isfile
(
path
))
with
open
(
path
,
'rb'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
zf
.
read
(
zi
))
for
opt
in
'-e'
,
'--extract'
:
with
temp_dir
()
as
extdir
:
out
=
self
.
zipfilecmd
(
opt
,
zip_name
,
extdir
)
self
.
assertEqual
(
out
,
b
''
)
with
zipfile
.
ZipFile
(
zip_name
)
as
zf
:
for
zi
in
zf
.
infolist
():
path
=
os
.
path
.
join
(
extdir
,
zi
.
filename
.
replace
(
'/'
,
os
.
sep
))
if
zi
.
is_dir
():
self
.
assertTrue
(
os
.
path
.
isdir
(
path
))
else
:
self
.
assertTrue
(
os
.
path
.
isfile
(
path
))
with
open
(
path
,
'rb'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
zf
.
read
(
zi
))
if
__name__
==
"__main__"
:
unittest
.
main
()
Lib/zipfile.py
Dosyayı görüntüle @
8c933105
...
...
@@ -1950,51 +1950,45 @@ class PyZipFile(ZipFile):
return
(
fname
,
archivename
)
def
main
(
args
=
None
):
import
textwrap
USAGE
=
textwrap
.
dedent
(
"""
\
Usage:
zipfile.py -l zipfile.zip # Show listing of a zipfile
zipfile.py -t zipfile.zip # Test if a zipfile is valid
zipfile.py -e zipfile.zip target # Extract zipfile into target dir
zipfile.py -c zipfile.zip src ... # Create zipfile from sources
"""
)
if
args
is
None
:
args
=
sys
.
argv
[
1
:]
if
not
args
or
args
[
0
]
not
in
(
'-l'
,
'-c'
,
'-e'
,
'-t'
):
print
(
USAGE
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
if
args
[
0
]
==
'-l'
:
if
len
(
args
)
!=
2
:
print
(
USAGE
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
with
ZipFile
(
args
[
1
],
'r'
)
as
zf
:
zf
.
printdir
()
elif
args
[
0
]
==
'-t'
:
if
len
(
args
)
!=
2
:
print
(
USAGE
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
with
ZipFile
(
args
[
1
],
'r'
)
as
zf
:
def
main
(
args
=
None
):
import
argparse
description
=
'A simple command line interface for zipfile module.'
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
group
=
parser
.
add_mutually_exclusive_group
()
group
.
add_argument
(
'-l'
,
'--list'
,
metavar
=
'<zipfile>'
,
help
=
'Show listing of a zipfile'
)
group
.
add_argument
(
'-e'
,
'--extract'
,
nargs
=
2
,
metavar
=
(
'<zipfile>'
,
'<output_dir>'
),
help
=
'Extract zipfile into target dir'
)
group
.
add_argument
(
'-c'
,
'--create'
,
nargs
=
'+'
,
metavar
=
(
'<name>'
,
'<file>'
),
help
=
'Create zipfile from sources'
)
group
.
add_argument
(
'-t'
,
'--test'
,
metavar
=
'<zipfile>'
,
help
=
'Test if a zipfile is valid'
)
args
=
parser
.
parse_args
(
args
)
if
args
.
test
is
not
None
:
src
=
args
.
test
with
ZipFile
(
src
,
'r'
)
as
zf
:
badfile
=
zf
.
testzip
()
if
badfile
:
print
(
"The following enclosed file is corrupted: {!r}"
.
format
(
badfile
))
print
(
"Done testing"
)
elif
args
[
0
]
==
'-e'
:
if
len
(
args
)
!=
3
:
print
(
USAGE
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
elif
args
.
list
is
not
None
:
src
=
args
.
list
with
ZipFile
(
src
,
'r'
)
as
zf
:
zf
.
printdir
(
)
with
ZipFile
(
args
[
1
],
'r'
)
as
zf
:
zf
.
extractall
(
args
[
2
])
elif
args
.
extract
is
not
None
:
src
,
curdir
=
args
.
extract
with
ZipFile
(
src
,
'r'
)
as
zf
:
zf
.
extractall
(
curdir
)
elif
args
[
0
]
==
'-c'
:
if
len
(
args
)
<
3
:
print
(
USAGE
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
elif
args
.
create
is
not
None
:
zip_name
=
args
.
create
.
pop
(
0
)
files
=
args
.
create
def
addToZip
(
zf
,
path
,
zippath
):
if
os
.
path
.
isfile
(
path
):
...
...
@@ -2007,8 +2001,8 @@ def main(args = None):
os
.
path
.
join
(
path
,
nm
),
os
.
path
.
join
(
zippath
,
nm
))
# else: ignore
with
ZipFile
(
args
[
1
]
,
'w'
)
as
zf
:
for
path
in
args
[
2
:]
:
with
ZipFile
(
zip_name
,
'w'
)
as
zf
:
for
path
in
files
:
zippath
=
os
.
path
.
basename
(
path
)
if
not
zippath
:
zippath
=
os
.
path
.
basename
(
os
.
path
.
dirname
(
path
))
...
...
@@ -2016,5 +2010,8 @@ def main(args = None):
zippath
=
''
addToZip
(
zf
,
path
,
zippath
)
else
:
parser
.
exit
(
2
,
parser
.
format_usage
())
if
__name__
==
"__main__"
:
main
()
Misc/NEWS
Dosyayı görüntüle @
8c933105
...
...
@@ -97,6 +97,9 @@ Core and Builtins
Library
-------
- Issue #28115: Command-line interface of the zipfile module now uses argparse.
Added support of long options.
- Issue #18219: Optimize csv.DictWriter for large number of columns.
Patch by Mariatta Wijaya.
...
...
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