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
cc2b3236
Commit
cc2b3236
authored
May 18, 1998
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
guess_extension(): New function. Performs a reverse mapping from MIME type
to filename extension.
parent
f2d2375f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
Lib/mimetypes.py
Lib/mimetypes.py
+18
-1
No files found.
Lib/mimetypes.py
View file @
cc2b3236
"""Guess the MIME type of a file.
This module defines
one useful function
:
This module defines
two useful functions
:
guess_type(url) -- guess the MIME type and encoding of a URL.
guess_extension(type) -- guess the extension for a given MIME type.
It also contains the following, for tuning the behavior:
Data:
...
...
@@ -64,6 +66,21 @@ def guess_type(url):
else
:
return
None
,
encoding
def
guess_extension
(
type
):
"""Guess the extension for a file based on its MIME type.
Return value is a string giving a filename extension, including the
leading dot ('.'). The extension is not guaranteed to have been
associated with any particular data stream, but has been known to be
used for streams of the MIME type given by `type'. If `type' is not
known, None is returned.
"""
type
=
string
.
lower
(
type
)
for
ext
,
stype
in
types_map
.
items
():
if
type
==
stype
:
return
ext
return
None
def
init
(
files
=
None
):
global
inited
for
file
in
files
or
knownfiles
:
...
...
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