Skip to content

Commit 2ba2aee

Browse files
committed
adding tests per @serhiy_storchaka's suggestion, not all pass yet
1 parent b9841d0 commit 2ba2aee

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lib/http/server.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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 \

0 commit comments

Comments
 (0)