summaryrefslogtreecommitdiff
path: root/Lib/mimetypes.py
diff options
context:
space:
mode:
authorMayank Asthana <mayankasthana1993@gmail.com>2018-10-10 20:16:44 +0530
committerAntoine Pitrou <pitrou@free.fr>2018-10-10 16:46:44 +0200
commit7e18deef652a9d413d5dbd19d61073ba7eb5460e (patch)
tree3f40e32bd110a4454934d01eb3796f65af9ea7ca /Lib/mimetypes.py
parent3058b7d85697f95573fa042d6b9e4d6e2a9e739c (diff)
downloadcpython-git-7e18deef652a9d413d5dbd19d61073ba7eb5460e.tar.gz
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.
Diffstat (limited to 'Lib/mimetypes.py')
-rw-r--r--Lib/mimetypes.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index bc647115b1..8861b75362 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -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: