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

Method guess_extension

Lib/mimetypes.py:221–237  ·  view source on GitHub ↗

Guess the extension for a file based on its MIME type. Return value is a string giving a filename extension, including the leading dot ('.'). The extension is not guaranteed to have been associated with any particular data stream, but would be mapped to the MIME typ

(self, type, strict=True)

Source from the content-addressed store, hash-verified

219 return extensions
220
221 def guess_extension(self, type, strict=True):
222 """Guess the extension for a file based on its MIME type.
223
224 Return value is a string giving a filename extension,
225 including the leading dot ('.'). The extension is not
226 guaranteed to have been associated with any particular data
227 stream, but would be mapped to the MIME type 'type' by
228 guess_type(). If no extension can be guessed for 'type', None
229 is returned.
230
231 Optional 'strict' argument when false adds a bunch of commonly found,
232 but non-standard types.
233 """
234 extensions = self.guess_all_extensions(type, strict)
235 if not extensions:
236 return None
237 return extensions[0]
238
239 def read(self, filename, strict=True):
240 """

Callers 8

mainFunction · 0.80
guess_extensionFunction · 0.80
test_file_parsingMethod · 0.80
check_extensionsMethod · 0.80

Calls 1

guess_all_extensionsMethod · 0.95

Tested by 5

test_file_parsingMethod · 0.64
check_extensionsMethod · 0.64