classification
Title: Remove urllib.parse._splittype from mimetypes.guess_type
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: mimetypes.guess_type("//example.com") misinterprets host name as file name
View: 22347
Assigned To: Nosy List: corona10, martin.panter, orsenthil
Priority: normal Keywords:

Created on 2019-02-08 08:14 by corona10, last changed 2019-09-05 12:19 by corona10. This issue is now closed.

Messages (2)
msg335061 - (view) Author: Dong-hee Na (corona10) * (Python triager) Date: 2019-02-08 08:14
Since urllib.parse.splittype is deprecated on 3.8.
In the future urllib.parse._splittype also should be removed.

I found that mimetypes.guess_type uses urllib.parse._splittype and
it can be replaced and it also looks like solve the issue mentioned on https://github.com/python/cpython/blame/e42b705188271da108de42b55d9344642170aa2b/Lib/test/test_urllib2.py#L749

And I checked that all unit tests are passed when

--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -114,7 +114,8 @@ class MimeTypes:
         but non-standard types.
         """
         url = os.fspath(url)
-        scheme, url = urllib.parse._splittype(url)
+        p = urllib.parse.urlparse(url)
+        scheme, url = p.scheme, p.path
         if scheme == 'data':
             # syntax of data URLs:
             # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 876fcd4199..0677390c2b 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -746,7 +746,7 @@ class HandlerTests(unittest.TestCase):
              ["foo", "bar"], "", None),
             ("ftp://localhost/baz.gif;type=a",
              "localhost", ftplib.FTP_PORT, "", "", "A",
-             [], "baz.gif", None),  # XXX really this should guess image/gif
+             [], "baz.gif", "image/gif"),
             ]:
             req = Request(url)
             req.timeout = None

I'd like to work on this issue if this proposal is accepted!
Always thanks
msg351169 - (view) Author: Dong-hee Na (corona10) * (Python triager) Date: 2019-09-05 01:43
This issue is fixed by
https://github.com/python/cpython/pull/15522
History
Date User Action Args
2019-09-05 12:19:43corona10setsuperseder: mimetypes.guess_type("//example.com") misinterprets host name as file name
resolution: fixed -> duplicate
2019-09-05 01:43:49corona10setstatus: open -> closed
versions: + Python 3.9
messages: + msg351169

resolution: fixed
stage: resolved
2019-02-09 02:16:14corona10setnosy: + martin.panter
2019-02-08 23:25:29martin.panterlinkissue22347 dependencies
2019-02-08 16:29:45SilentGhostsetnosy: + orsenthil
2019-02-08 08:24:05corona10setversions: + Python 3.7
2019-02-08 08:14:43corona10create