Skip to content

gh-136507: Fix mimetypes CLI cannot handle multiple file parameters #136508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,18 +722,23 @@ def _main(args=None):

args, help_text = _parse_args(args)

results = []
if args.extension:
for gtype in args.type:
guess = guess_extension(gtype, not args.lenient)
if guess:
return str(guess)
sys.exit(f"error: unknown type {gtype}")
results.append(str(guess))
else:
sys.exit(f"error: unknown type {gtype}")
return '\n'.join(results)
else:
for gtype in args.type:
guess, encoding = guess_type(gtype, not args.lenient)
if guess:
return f"type: {guess} encoding: {encoding}"
sys.exit(f"error: media type unknown for {gtype}")
results.append(f"type: {guess} encoding: {encoding}")
else:
sys.exit(f"error: media type unknown for {gtype}")
return '\n'.join(results)
return help_text


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix mimetypes CLI cannot handle multiple file parameters
Loading