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
9fc720e5
Commit
9fc720e5
authored
Jun 24, 2019
by
David K. Hess
Committed by
Steve Dower
Jun 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-4963: Fix for initialization and non-deterministic behavior issues in mimetypes (GH-3062)
parent
8bd2872a
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
188 additions
and
120 deletions
+188
-120
Doc/library/mimetypes.rst
Doc/library/mimetypes.rst
+4
-0
Lib/mimetypes.py
Lib/mimetypes.py
+131
-120
Lib/test/test_mimetypes.py
Lib/test/test_mimetypes.py
+51
-0
Misc/NEWS.d/next/Library/2017-08-15-11-24-41.bpo-4963.LRYres.rst
...WS.d/next/Library/2017-08-15-11-24-41.bpo-4963.LRYres.rst
+2
-0
No files found.
Doc/library/mimetypes.rst
View file @
9fc720e5
...
...
@@ -93,6 +93,10 @@ behavior of the module.
Specifying an empty list for *files* will prevent the system defaults from
being applied: only the well-known values will be present from a built-in list.
If *files* is ``None`` the internal data structure is completely rebuilt to its
initial default value. This is a stable operation and will produce the same results
when called multiple times.
.. versionchanged:: 3.2
Previously, Windows registry settings were ignored.
...
...
Lib/mimetypes.py
View file @
9fc720e5
This diff is collapsed.
Click to expand it.
Lib/test/test_mimetypes.py
View file @
9fc720e5
...
...
@@ -79,6 +79,57 @@ class MimeTypesTestCase(unittest.TestCase):
strict
=
True
)
self
.
assertEqual
(
exts
,
[
'.g3'
,
'.g
\
xb3
'
])
def
test_init_reinitializes
(
self
):
# Issue 4936: make sure an init starts clean
# First, put some poison into the types table
mimetypes
.
add_type
(
'foo/bar'
,
'.foobar'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'foo/bar'
),
'.foobar'
)
# Reinitialize
mimetypes
.
init
()
# Poison should be gone.
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'foo/bar'
),
None
)
def
test_preferred_extension
(
self
):
def
check_extensions
():
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'application/octet-stream'
),
'.bin'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'application/postscript'
),
'.ps'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'application/vnd.apple.mpegurl'
),
'.m3u'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'application/vnd.ms-excel'
),
'.xls'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'application/vnd.ms-powerpoint'
),
'.ppt'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'application/x-texinfo'
),
'.texi'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'application/x-troff'
),
'.roff'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'application/xml'
),
'.xsl'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'audio/mpeg'
),
'.mp3'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'image/jpeg'
),
'.jpg'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'image/tiff'
),
'.tiff'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'message/rfc822'
),
'.eml'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'text/html'
),
'.html'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'text/plain'
),
'.txt'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'video/mpeg'
),
'.mpeg'
)
self
.
assertEqual
(
mimetypes
.
guess_extension
(
'video/quicktime'
),
'.mov'
)
check_extensions
()
mimetypes
.
init
()
check_extensions
()
def
test_init_stability
(
self
):
mimetypes
.
init
()
suffix_map
=
mimetypes
.
suffix_map
encodings_map
=
mimetypes
.
encodings_map
types_map
=
mimetypes
.
types_map
common_types
=
mimetypes
.
common_types
mimetypes
.
init
()
self
.
assertIsNot
(
suffix_map
,
mimetypes
.
suffix_map
)
self
.
assertIsNot
(
encodings_map
,
mimetypes
.
encodings_map
)
self
.
assertIsNot
(
types_map
,
mimetypes
.
types_map
)
self
.
assertIsNot
(
common_types
,
mimetypes
.
common_types
)
self
.
assertEqual
(
suffix_map
,
mimetypes
.
suffix_map
)
self
.
assertEqual
(
encodings_map
,
mimetypes
.
encodings_map
)
self
.
assertEqual
(
types_map
,
mimetypes
.
types_map
)
self
.
assertEqual
(
common_types
,
mimetypes
.
common_types
)
def
test_path_like_ob
(
self
):
filename
=
"LICENSE.txt"
filepath
=
pathlib
.
Path
(
filename
)
...
...
Misc/NEWS.d/next/Library/2017-08-15-11-24-41.bpo-4963.LRYres.rst
0 → 100644
View file @
9fc720e5
Fixed non-deterministic behavior related to mimetypes extension mapping and
module reinitialization.
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