MCPcopy Index your code
hub / github.com/python/cpython / guess_type

Method guess_type

Lib/http/server.py:916–939  ·  view source on GitHub ↗

Guess the type of a file. Argument is a PATH (a filename). Return value is a string of the form type/subtype, usable for a MIME Content-type header. The default implementation looks the file's extension up in the table self.extensions_map, using application

(self, path)

Source from the content-addressed store, hash-verified

914 shutil.copyfileobj(source, outputfile)
915
916 def guess_type(self, path):
917 """Guess the type of a file.
918
919 Argument is a PATH (a filename).
920
921 Return value is a string of the form type/subtype,
922 usable for a MIME Content-type header.
923
924 The default implementation looks the file's extension
925 up in the table self.extensions_map, using application/octet-stream
926 as a default; however it would be permissible (if
927 slow) to look inside the data to make a better guess.
928
929 """
930 base, ext = posixpath.splitext(path)
931 if ext in self.extensions_map:
932 return self.extensions_map[ext]
933 ext = ext.lower()
934 if ext in self.extensions_map:
935 return self.extensions_map[ext]
936 guess, _ = mimetypes.guess_file_type(path)
937 if guess:
938 return guess
939 return 'application/octet-stream'
940
941
942nobody = None

Callers 9

send_headMethod · 0.95
test_case_sensitivityMethod · 0.45
test_urlMethod · 0.45
test_path_like_obMethod · 0.45
test_registry_parsingMethod · 0.45
ftp_openMethod · 0.45

Calls 3

splitextMethod · 0.80
guess_file_typeMethod · 0.80
lowerMethod · 0.45

Tested by 7

test_case_sensitivityMethod · 0.36
test_urlMethod · 0.36
test_path_like_obMethod · 0.36
test_registry_parsingMethod · 0.36