MCPcopy Create free account
hub / github.com/python/cpython / guess_type

Function guess_type

Lib/mimetypes.py:322–342  ·  view source on GitHub ↗

Guess the type of a file based on its URL. Return value is a tuple (type, encoding) where type is None if the type can't be guessed (no or unknown suffix) or a string of the form type/subtype, usable for a MIME Content-type header; and encoding is None for no encoding or the name of

(url, strict=True)

Source from the content-addressed store, hash-verified

320 continue
321
322def guess_type(url, strict=True):
323 """Guess the type of a file based on its URL.
324
325 Return value is a tuple (type, encoding) where type is None if the
326 type can't be guessed (no or unknown suffix) or a string of the
327 form type/subtype, usable for a MIME Content-type header; and
328 encoding is None for no encoding or the name of the program used
329 to encode (e.g. compress or gzip). The mappings are table
330 driven. Encoding suffixes are case sensitive; type suffixes are
331 first tried case sensitive, then case insensitive.
332
333 The suffixes .tgz, .taz and .tz (case sensitive!) are all mapped
334 to ".tar.gz". (This is table-driven too, using the dictionary
335 suffix_map).
336
337 Optional 'strict' argument when false adds a bunch of commonly found, but
338 non-standard types.
339 """
340 if _db is None:
341 init()
342 return _db.guess_type(url, strict)
343
344
345def guess_file_type(path, *, strict=True):

Callers 2

_mainFunction · 0.85
test_data_urlsMethod · 0.85

Calls 2

initFunction · 0.70
guess_typeMethod · 0.45

Tested by 1

test_data_urlsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…