Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e8bbc52d
Commit
e8bbc52d
authored
Oct 10, 2018
by
Stéphane Wirtel
Committed by
Julien Palard
Oct 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-23596: Use argparse for the command line of gzip (GH-9781)
Co-authored-by:
Antony Lee
<
anntzer.lee@gmail.com
>
parent
84eec119
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
Lib/gzip.py
Lib/gzip.py
+12
-13
Misc/NEWS.d/next/Tests/2018-10-09-23-51-07.bpo-23596.rdnert.rst
...EWS.d/next/Tests/2018-10-09-23-51-07.bpo-23596.rdnert.rst
+1
-0
No files found.
Lib/gzip.py
View file @
e8bbc52d
...
...
@@ -532,18 +532,17 @@ def decompress(data):
return
f
.
read
()
def
_test
():
# Act like gzip; with -d, act like gunzip.
# The input file is not deleted, however, nor are any other gzip
# options or features supported.
args
=
sys
.
argv
[
1
:]
decompress
=
args
and
args
[
0
]
==
"-d"
if
decompress
:
args
=
args
[
1
:]
if
not
args
:
args
=
[
"-"
]
for
arg
in
args
:
if
decompress
:
def
main
():
from
argparse
import
ArgumentParser
parser
=
ArgumentParser
(
description
=
"A simple command line interface for the gzip module: act like gzip, "
"but do not delete the input file."
)
parser
.
add_argument
(
"-d"
,
"--decompress"
,
action
=
"store_true"
,
help
=
"act like gunzip instead of gzip"
)
parser
.
add_argument
(
"args"
,
nargs
=
"*"
,
default
=
[
"-"
],
metavar
=
'file'
)
args
=
parser
.
parse_args
()
for
arg
in
args
.
args
:
if
args
.
decompress
:
if
arg
==
"-"
:
f
=
GzipFile
(
filename
=
""
,
mode
=
"rb"
,
fileobj
=
sys
.
stdin
.
buffer
)
g
=
sys
.
stdout
.
buffer
...
...
@@ -571,4 +570,4 @@ def _test():
f
.
close
()
if
__name__
==
'__main__'
:
_test
()
main
()
Misc/NEWS.d/next/Tests/2018-10-09-23-51-07.bpo-23596.rdnert.rst
0 → 100644
View file @
e8bbc52d
Use argparse for the command line of the gzip module. Patch by Antony Lee
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