classification
Title: Remove urllib.parse._splittype from mimetypes.guess_type
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: corona10, martin.panter, orsenthil
Priority: normal Keywords:

Created on 2019-02-08 08:14 by corona10, last changed 2019-02-09 02:16 by corona10.

Messages (1)
msg335061 - (view) Author: Dong-hee Na (corona10) * 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
History
Date User Action Args
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