]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.8] bpo-38449: Revert "bpo-22347: Update mimetypes.guess_type to allow oper parsing...
authorAbhilash Raj <maxking@users.noreply.github.com>
Sat, 12 Oct 2019 16:58:11 +0000 (09:58 -0700)
committerGitHub <noreply@github.com>
Sat, 12 Oct 2019 16:58:11 +0000 (09:58 -0700)
This reverts commit 87bd2071c756188b6cd577889fb1682831142ceb.

The reason for revert is a regression caused by the change in 3.8.0rc1, see bpo-38449 for more details.

https://bugs.python.org/issue38449
(cherry picked from commit 19a3d873005e5730eeabdc394c961e93f2ec02f0)

Co-authored-by: Abhilash Raj <maxking@users.noreply.github.com>
Lib/mimetypes.py
Lib/test/test_mimetypes.py
Lib/test/test_urllib2.py
Misc/NEWS.d/next/Library/2019-10-11-18-49-00.bpo-38449.9TWMlz.rst [new file with mode: 0644]

index 9fdd6ebd6348f2f2046d805e812169b7404b175a..9b42bf6dd2ca74ad924969b4392df92c93cef5c0 100644 (file)
@@ -114,8 +114,7 @@ class MimeTypes:
         but non-standard types.
         """
         url = os.fspath(url)
-        p = urllib.parse.urlparse(url)
-        scheme, url = p.scheme, p.path
+        scheme, url = urllib.parse._splittype(url)
         if scheme == 'data':
             # syntax of data URLs:
             # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
index 7761c3fe867a7ea78f97f3e476c19f1517678032..bfd5eeedaa77b47ea5f12772f9f42a9314df1690 100644 (file)
@@ -51,14 +51,6 @@ class MimeTypesTestCase(unittest.TestCase):
         eq(self.db.guess_type('foo.xul', strict=False), ('text/xul', None))
         eq(self.db.guess_extension('image/jpg', strict=False), '.jpg')
 
-    def test_url(self):
-        result = self.db.guess_type('http://host.html')
-        msg = 'URL only has a host name, not a file'
-        self.assertSequenceEqual(result, (None, None), msg)
-        result = self.db.guess_type('http://example.com/host.html')
-        msg = 'Should be text/html'
-        self.assertSequenceEqual(result, ('text/html', None), msg)
-
     def test_guess_all_types(self):
         eq = self.assertEqual
         unless = self.assertTrue
index e7e80bc5dabfe2d5f52a5bd1efb37ea3fc4d5944..61e3ecc612d6c99d773c7d6b833fce307af21af8 100644 (file)
@@ -744,7 +744,7 @@ class HandlerTests(unittest.TestCase):
              ["foo", "bar"], "", None),
             ("ftp://localhost/baz.gif;type=a",
              "localhost", ftplib.FTP_PORT, "", "", "A",
-             [], "baz.gif", "image/gif"),
+             [], "baz.gif", None),  # XXX really this should guess image/gif
             ]:
             req = Request(url)
             req.timeout = None
diff --git a/Misc/NEWS.d/next/Library/2019-10-11-18-49-00.bpo-38449.9TWMlz.rst b/Misc/NEWS.d/next/Library/2019-10-11-18-49-00.bpo-38449.9TWMlz.rst
new file mode 100644 (file)
index 0000000..f7b1dbf
--- /dev/null
@@ -0,0 +1,2 @@
+Revert GH-15522, which introduces a regression in
+:meth:`mimetypes.guess_type` due to improper handling of filenames as urls.