Skip to content

gh-136507: Fix mimetypes CLI to 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 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix mimetypes CLI cannot handle multiple file parameters
  • Loading branch information
Wulian233 committed Jul 10, 2025
commit 69ae20cc696a68546b3978da0c8d8e09c0a1a1e7
18 changes: 11 additions & 7 deletions Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,25 +717,29 @@ def _parse_args(args):


def _main(args=None):
"""Run the mimetypes command-line interface and return a text to print."""
"""Run the mimetypes command-line interface."""
import sys

args, help_text = _parse_args(args)
if not args.type:
print(help_text)
return

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}")
print(str(guess))
else:
print(f"error: unknown type {gtype}", file=sys.stderr)
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}")
return help_text
print(f"type: {guess} encoding: {encoding}")
else:
print(f"error: media type unknown for {gtype}", file=sys.stderr)


if __name__ == '__main__':
print(_main())
_main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix mimetypes CLI cannot handle multiple file parameters
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy