Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
87bd2071
Commit
87bd2071
authored
Sep 05, 2019
by
Dong-hee Na
Committed by
Miss Islington (bot)
Sep 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-22347: Update mimetypes.guess_type to allow proper parsing of URLs (GH-15522)
https://bugs.python.org/issue22347
parent
6cd9666c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
2 deletions
+13
-2
Lib/mimetypes.py
Lib/mimetypes.py
+2
-1
Lib/test/test_mimetypes.py
Lib/test/test_mimetypes.py
+8
-0
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+1
-1
Misc/NEWS.d/next/Library/2019-08-27-01-03-26.bpo-22347._TRpYr.rst
...S.d/next/Library/2019-08-27-01-03-26.bpo-22347._TRpYr.rst
+2
-0
No files found.
Lib/mimetypes.py
View file @
87bd2071
...
...
@@ -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
...
...
Lib/test/test_mimetypes.py
View file @
87bd2071
...
...
@@ -51,6 +51,14 @@ 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
...
...
Lib/test/test_urllib2.py
View file @
87bd2071
...
...
@@ -742,7 +742,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
...
...
Misc/NEWS.d/next/Library/2019-08-27-01-03-26.bpo-22347._TRpYr.rst
0 → 100644
View file @
87bd2071
Update mimetypes.guess_type to allow proper parsing of URLs with only a host name.
Patch by Dong-hee Na.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment