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

Function guess_extension

Lib/mimetypes.py:372–386  ·  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 type 'type' by gues

(type, strict=True)

Source from the content-addressed store, hash-verified

370 return _db.guess_all_extensions(type, strict)
371
372def guess_extension(type, strict=True):
373 """Guess the extension for a file based on its MIME type.
374
375 Return value is a string giving a filename extension, including the
376 leading dot ('.'). The extension is not guaranteed to have been
377 associated with any particular data stream, but would be mapped to the
378 MIME type 'type' by guess_type(). If no extension can be guessed for
379 'type', None is returned.
380
381 Optional 'strict' argument when false adds a bunch of commonly found,
382 but non-standard types.
383 """
384 if _db is None:
385 init()
386 return _db.guess_extension(type, strict)
387
388def add_type(type, ext, strict=True):
389 """Add a mapping between a type and an extension.

Callers 1

_mainFunction · 0.85

Calls 2

guess_extensionMethod · 0.80
initFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…