diff options
author | Abhilash Raj <maxking@users.noreply.github.com> | 2019-10-12 11:50:03 -0700 |
---|---|---|
committer | Ned Deily <nad@python.org> | 2019-10-14 17:27:49 -0400 |
commit | 2a405598bbccbc42710dc5ecf3d44c8de4c16582 (patch) | |
tree | a37387c25656d1c73607530899ec91c1932b514a | |
parent | Fix typo: equivalent code of `async with cond` (GH-11681) (GH-16720) (diff) | |
download | cpython-2a405598bbccbc42710dc5ecf3d44c8de4c16582.tar.gz cpython-2a405598bbccbc42710dc5ecf3d44c8de4c16582.tar.bz2 cpython-2a405598bbccbc42710dc5ecf3d44c8de4c16582.zip |
[3.7] bpo-38449: Revert "bpo-22347: Update mimetypes.guess_type to allow oper parsing of URLs (GH-15685)" (GH-16724) (GH-16727)
Reverts GH-15687 which caused the issue.
https://bugs.python.org/issue22347
https://bugs.python.org/issue38449
-rw-r--r-- | Lib/mimetypes.py | 3 | ||||
-rw-r--r-- | Lib/test/test_mimetypes.py | 8 | ||||
-rw-r--r-- | Lib/test/test_urllib2.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-10-12-08-57-34.bpo-38449.9TWMlz.rst | 2 |
4 files changed, 4 insertions, 11 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index b5e1ce1ca10..bcf522835f4 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -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 diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index 2f26edeb990..adbec8dab42 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -50,14 +50,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 diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 0677390c2b0..876fcd4199f 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", "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-12-08-57-34.bpo-38449.9TWMlz.rst b/Misc/NEWS.d/next/Library/2019-10-12-08-57-34.bpo-38449.9TWMlz.rst new file mode 100644 index 00000000000..f7b1dbf8d89 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-10-12-08-57-34.bpo-38449.9TWMlz.rst @@ -0,0 +1,2 @@ +Revert GH-15522, which introduces a regression in +:meth:`mimetypes.guess_type` due to improper handling of filenames as urls. |