MCPcopy Index your code
hub / github.com/RustPython/RustPython / guess_type

Method guess_type

Lib/http/server.py:944–967  ·  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

942 shutil.copyfileobj(source, outputfile)
943
944 def guess_type(self, path):
945 """Guess the type of a file.
946
947 Argument is a PATH (a filename).
948
949 Return value is a string of the form type/subtype,
950 usable for a MIME Content-type header.
951
952 The default implementation looks the file's extension
953 up in the table self.extensions_map, using application/octet-stream
954 as a default; however it would be permissible (if
955 slow) to look inside the data to make a better guess.
956
957 """
958 base, ext = posixpath.splitext(path)
959 if ext in self.extensions_map:
960 return self.extensions_map[ext]
961 ext = ext.lower()
962 if ext in self.extensions_map:
963 return self.extensions_map[ext]
964 guess, _ = mimetypes.guess_file_type(path)
965 if guess:
966 return guess
967 return 'application/octet-stream'
968
969
970# Utilities for CGIHTTPRequestHandler

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