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
df3cbe8f
Commit
df3cbe8f
authored
Feb 09, 2001
by
Eric S. Raymond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
String method conversion. Added a trivial main to test it with.
parent
a27cf43e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
Lib/mimetypes.py
Lib/mimetypes.py
+10
-7
No files found.
Lib/mimetypes.py
View file @
df3cbe8f
...
@@ -23,7 +23,6 @@ read_mime_types(file) -- parse one file, return a dictionary or None
...
@@ -23,7 +23,6 @@ read_mime_types(file) -- parse one file, return a dictionary or None
"""
"""
import
string
import
posixpath
import
posixpath
import
urllib
import
urllib
...
@@ -64,11 +63,11 @@ def guess_type(url):
...
@@ -64,11 +63,11 @@ def guess_type(url):
# data := *urlchar
# data := *urlchar
# parameter := attribute "=" value
# parameter := attribute "=" value
# type/subtype defaults to "text/plain"
# type/subtype defaults to "text/plain"
comma
=
string
.
find
(
url
,
','
)
comma
=
url
.
find
(
','
)
if
comma
<
0
:
if
comma
<
0
:
# bad data URL
# bad data URL
return
None
,
None
return
None
,
None
semi
=
string
.
find
(
url
,
';'
,
0
,
comma
)
semi
=
url
.
find
(
';'
,
0
,
comma
)
if
semi
>=
0
:
if
semi
>=
0
:
type
=
url
[:
semi
]
type
=
url
[:
semi
]
else
:
else
:
...
@@ -86,8 +85,8 @@ def guess_type(url):
...
@@ -86,8 +85,8 @@ def guess_type(url):
encoding
=
None
encoding
=
None
if
types_map
.
has_key
(
ext
):
if
types_map
.
has_key
(
ext
):
return
types_map
[
ext
],
encoding
return
types_map
[
ext
],
encoding
elif
types_map
.
has_key
(
string
.
lower
(
ext
)):
elif
types_map
.
has_key
(
ext
.
lower
(
)):
return
types_map
[
string
.
lower
(
ext
)],
encoding
return
types_map
[
ext
.
lower
(
)],
encoding
else
:
else
:
return
None
,
encoding
return
None
,
encoding
...
@@ -103,7 +102,7 @@ def guess_extension(type):
...
@@ -103,7 +102,7 @@ def guess_extension(type):
global
inited
global
inited
if
not
inited
:
if
not
inited
:
init
()
init
()
type
=
string
.
lower
(
type
)
type
=
type
.
lower
(
)
for
ext
,
stype
in
types_map
.
items
():
for
ext
,
stype
in
types_map
.
items
():
if
type
==
stype
:
if
type
==
stype
:
return
ext
return
ext
...
@@ -127,7 +126,7 @@ def read_mime_types(file):
...
@@ -127,7 +126,7 @@ def read_mime_types(file):
while
1
:
while
1
:
line
=
f
.
readline
()
line
=
f
.
readline
()
if
not
line
:
break
if
not
line
:
break
words
=
string
.
split
(
line
)
words
=
line
.
split
(
)
for
i
in
range
(
len
(
words
)):
for
i
in
range
(
len
(
words
)):
if
words
[
i
][
0
]
==
'#'
:
if
words
[
i
][
0
]
==
'#'
:
del
words
[
i
:]
del
words
[
i
:]
...
@@ -237,3 +236,7 @@ types_map = {
...
@@ -237,3 +236,7 @@ types_map = {
'.xwd'
:
'image/x-xwindowdump'
,
'.xwd'
:
'image/x-xwindowdump'
,
'.zip'
:
'application/zip'
,
'.zip'
:
'application/zip'
,
}
}
if
__name__
==
'__main__'
:
import
sys
print
guess_type
(
sys
.
argv
[
1
])
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