File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -891,6 +891,26 @@ 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
904+ >>> 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+
894914 """
895915 base , ext = posixpath .splitext (path )
896916 return self .extensions_map .get (ext ) or \
You can’t perform that action at this time.
0 commit comments