@@ -891,32 +891,17 @@ def guess_type(self, path):
891891 as a default; however it would be permissible (if
892892 slow) to look inside the data to make a better guess.
893893
894- >>> testserver = type('', (), {
895- ... 'makefile': lambda mode, bufsize: open(os.devnull, mode)
896- ... })
897- >>> testhandler = SimpleHTTPRequestHandler(testserver, None, None)
898- >>> testhandler.guess_type('/foo.bar.GZ') # tests ext.lower()
899- 'application/gzip'
900- >>> testhandler.default_content_type = 'nonesuch/nonesuch'
901- >>> testhandler.guess_type('/this/should/give/default')
902- 'nonesuch/nonesuch'
903- >>> # check short-circuiting works using mock mimetypes.guess_type
904- >>> sys.modules[__name__].mimetypes = type('', (), {
905- ... 'guess_type': lambda x: (print('foo'), print('bar'))
906- ... })
907- >>> testhandler.guess_type('/should/show/foo/bar/then/default')
908- foo
909- bar
910- 'nonesuch/nonesuch'
911- >>> testhandler.guess_type('/should/not/print/foo.Z')
912- 'application/octet-stream'
913-
914894 """
915895 base , ext = posixpath .splitext (path )
916- return self .extensions_map .get (ext ) or \
917- self .extensions_map .get (ext .lower ()) or \
918- mimetypes .guess_type (path )[0 ] or \
919- self .default_content_type
896+ if ext in self .extensions_map :
897+ return self .extensions_map [ext ]
898+ ext = ext .lower ()
899+ if ext in self .extensions_map :
900+ return self .extensions_map [ext ]
901+ guess , _ = mimetypes .guess_type (path )
902+ if guess :
903+ return guess
904+ return self .default_content_type
920905
921906
922907# Utilities for CGIHTTPRequestHandler
0 commit comments