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)
| 320 | continue |
| 321 | |
| 322 | def 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 | |
| 345 | def guess_file_type(path, *, strict=True): |
searching dependent graphs…