mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-34926: Make mimetypes.guess_type accept os.PathLike objects (GH-9777)
:meth:`mimetypes.MimeTypes.guess_type` now accepts :term:`path-like object` in addition to url strings.
This commit is contained in:
parent
3058b7d856
commit
7e18deef65
4 changed files with 35 additions and 3 deletions
|
@ -95,7 +95,7 @@ class MimeTypes:
|
|||
exts.append(ext)
|
||||
|
||||
def guess_type(self, url, strict=True):
|
||||
"""Guess the type of a file based on its URL.
|
||||
"""Guess the type of a file which is either a URL or a path-like object.
|
||||
|
||||
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
|
||||
|
@ -113,6 +113,7 @@ class MimeTypes:
|
|||
Optional `strict' argument when False adds a bunch of commonly found,
|
||||
but non-standard types.
|
||||
"""
|
||||
url = os.fspath(url)
|
||||
scheme, url = urllib.parse._splittype(url)
|
||||
if scheme == 'data':
|
||||
# syntax of data URLs:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue