Skip to content

Commit 5a638a8

Browse files
authored
[3.8] bpo-38449: Revert "bpo-22347: Update mimetypes.guess_type to allow oper parsing of URLs" (GH-16724) (GH-16728)
This reverts commit 87bd207. 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 19a3d87) Co-authored-by: Abhilash Raj <[email protected]>
1 parent 1da648a commit 5a638a8

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

Lib/mimetypes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ def guess_type(self, url, strict=True):
114114
but non-standard types.
115115
"""
116116
url = os.fspath(url)
117-
p = urllib.parse.urlparse(url)
118-
scheme, url = p.scheme, p.path
117+
scheme, url = urllib.parse._splittype(url)
119118
if scheme == 'data':
120119
# syntax of data URLs:
121120
# dataurl := "data:" [ mediatype ] [ ";base64" ] "," data

Lib/test/test_mimetypes.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ def test_non_standard_types(self):
5151
eq(self.db.guess_type('foo.xul', strict=False), ('text/xul', None))
5252
eq(self.db.guess_extension('image/jpg', strict=False), '.jpg')
5353

54-
def test_url(self):
55-
result = self.db.guess_type('http://host.html')
56-
msg = 'URL only has a host name, not a file'
57-
self.assertSequenceEqual(result, (None, None), msg)
58-
result = self.db.guess_type('http://example.com/host.html')
59-
msg = 'Should be text/html'
60-
self.assertSequenceEqual(result, ('text/html', None), msg)
61-
6254
def test_guess_all_types(self):
6355
eq = self.assertEqual
6456
unless = self.assertTrue

Lib/test/test_urllib2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ def connect_ftp(self, user, passwd, host, port, dirs,
744744
["foo", "bar"], "", None),
745745
("ftp://localhost/baz.gif;type=a",
746746
"localhost", ftplib.FTP_PORT, "", "", "A",
747-
[], "baz.gif", "image/gif"),
747+
[], "baz.gif", None), # XXX really this should guess image/gif
748748
]:
749749
req = Request(url)
750750
req.timeout = None
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Revert GH-15522, which introduces a regression in
2+
:meth:`mimetypes.guess_type` due to improper handling of filenames as urls.

0 commit comments

Comments
 (0)