summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhilash Raj <maxking@users.noreply.github.com>2019-10-11 22:41:35 -0700
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-10-11 22:41:35 -0700
commit19a3d873005e5730eeabdc394c961e93f2ec02f0 (patch)
tree888187697cbe6cd398211a1ba309a313a934ffbe
parent2b7dc40b2af6578181808ba73c1533fc114e55df (diff)
downloadcpython-git-19a3d873005e5730eeabdc394c961e93f2ec02f0.tar.gz
bpo-38449: Revert "bpo-22347: Update mimetypes.guess_type to allow oper parsing of URLs (GH-15522)" (GH-16724)
This reverts commit 87bd2071c756188b6cd577889fb1682831142ceb. https://bugs.python.org/issue38449
-rw-r--r--Lib/mimetypes.py3
-rw-r--r--Lib/test/test_mimetypes.py8
-rw-r--r--Lib/test/test_urllib2.py2
-rw-r--r--Misc/NEWS.d/next/Library/2019-08-27-01-03-26.bpo-22347._TRpYr.rst2
-rw-r--r--Misc/NEWS.d/next/Library/2019-10-11-18-49-00.bpo-38449.9TWMlz.rst2
5 files changed, 4 insertions, 13 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 9fdd6ebd63..9b42bf6dd2 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 7761c3fe86..bfd5eeedaa 100644
--- a/Lib/test/test_mimetypes.py
+++ b/Lib/test/test_mimetypes.py
@@ -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
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 186a967659..8abedaac98 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -742,7 +742,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-08-27-01-03-26.bpo-22347._TRpYr.rst b/Misc/NEWS.d/next/Library/2019-08-27-01-03-26.bpo-22347._TRpYr.rst
deleted file mode 100644
index 1a3c199382..0000000000
--- a/Misc/NEWS.d/next/Library/2019-08-27-01-03-26.bpo-22347._TRpYr.rst
+++ /dev/null
@@ -1,2 +0,0 @@
-Update mimetypes.guess_type to allow proper parsing of URLs with only a host name.
-Patch by Dong-hee Na.
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
index 0000000000..f7b1dbf8d8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-10-11-18-49-00.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.