Skip to content

Commit 26bec36

Browse files
committed
Temporarily rollback everything but tests
1 parent 3368be4 commit 26bec36

File tree

1 file changed

+43
-31
lines changed

1 file changed

+43
-31
lines changed

Lib/mimetypes.py

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ def _default_mime_types():
517517
'.aiff' : 'audio/x-aiff',
518518
'.ra' : 'audio/x-pn-realaudio',
519519
'.wav' : 'audio/x-wav',
520-
'.avif' : 'image/avif',
521520
'.bmp' : 'image/bmp',
522521
'.gif' : 'image/gif',
523522
'.ief' : 'image/ief',
@@ -590,7 +589,6 @@ def _default_mime_types():
590589
'.pict': 'image/pict',
591590
'.pct' : 'image/pict',
592591
'.pic' : 'image/pict',
593-
'.webp': 'image/webp',
594592
'.xul' : 'text/xul',
595593
}
596594

@@ -599,35 +597,49 @@ def _default_mime_types():
599597

600598

601599
def _main():
602-
from argparse import ArgumentParser
603-
parser = ArgumentParser(description='map filename extensions to MIME types')
604-
parser.add_argument(
605-
'-e', '--extension',
606-
action='store_true',
607-
help='guess extension instead of type'
608-
)
609-
parser.add_argument(
610-
'-l', '--lenient',
611-
action='store_true',
612-
help='additianally search for common but non-standard types'
613-
)
614-
parser.add_argument('type', nargs='+', help='a type to search')
615-
arguments = parser.parse_args()
616-
617-
if arguments.extension:
618-
for gtype in arguments.type:
619-
guess = guess_extension(gtype, not arguments.lenient)
620-
if guess:
621-
print(guess)
622-
else:
623-
print("I don't know anything about type", gtype)
624-
else:
625-
for gtype in arguments.type:
626-
guess, encoding = guess_type(gtype, not arguments.lenient)
627-
if guess:
628-
print('type:', guess, 'encoding:', encoding)
629-
else:
630-
print("I don't know anything about type", gtype)
600+
import getopt
601+
602+
USAGE = """\
603+
Usage: mimetypes.py [options] type
604+
605+
Options:
606+
--help / -h -- print this message and exit
607+
--lenient / -l -- additionally search of some common, but non-standard
608+
types.
609+
--extension / -e -- guess extension instead of type
610+
611+
More than one type argument may be given.
612+
"""
613+
614+
def usage(code, msg=''):
615+
print(USAGE)
616+
if msg: print(msg)
617+
sys.exit(code)
618+
619+
try:
620+
opts, args = getopt.getopt(sys.argv[1:], 'hle',
621+
['help', 'lenient', 'extension'])
622+
except getopt.error as msg:
623+
usage(1, msg)
624+
625+
strict = 1
626+
extension = 0
627+
for opt, arg in opts:
628+
if opt in ('-h', '--help'):
629+
usage(0)
630+
elif opt in ('-l', '--lenient'):
631+
strict = 0
632+
elif opt in ('-e', '--extension'):
633+
extension = 1
634+
for gtype in args:
635+
if extension:
636+
guess = guess_extension(gtype, strict)
637+
if not guess: print("I don't know anything about type", gtype)
638+
else: print(guess)
639+
else:
640+
guess, encoding = guess_type(gtype, strict)
641+
if not guess: print("I don't know anything about type", gtype)
642+
else: print('type:', guess, 'encoding:', encoding)
631643

632644

633645
if __name__ == '__main__':

0 commit comments

Comments
 (0)