Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
bfc3944b
Kaydet (Commit)
bfc3944b
authored
Mar 25, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Change by Andrew Kuchling (edited by Guido):
Removed unused import tempfile. Added some docstrings.
üst
31ef35b8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
17 deletions
+32
-17
mailcap.py
Lib/mailcap.py
+32
-17
No files found.
Lib/mailcap.py
Dosyayı görüntüle @
bfc3944b
# Mailcap file handling. See RFC 1524.
"""Mailcap file handling. See RFC 1524."""
import
os
import
string
import
tempfile
# Part 1: top-level interface.
def
getcaps
():
"""Return a dictionary containing the mailcap database.
The dictionary maps a MIME type (in all lowercase,
e.g. 'text/plain') to a list of corresponding mailcap entries.
"""
caps
=
{}
for
mailcap
in
listmailcapfiles
():
try
:
...
...
@@ -24,6 +29,7 @@ def getcaps():
return
caps
def
listmailcapfiles
():
"""Return a list of all mailcap files found on the system."""
# XXX Actually, this is Unix-specific
if
os
.
environ
.
has_key
(
'MAILCAPS'
):
str
=
os
.
environ
[
'MAILCAPS'
]
...
...
@@ -112,30 +118,39 @@ def parsefield(line, i, n):
# Part 3: using the database.
def
findmatch
(
caps
,
type
,
key
=
'view'
,
filename
=
"/dev/null"
,
plist
=
[]):
entries
=
lookup
(
caps
,
type
,
key
)
def
findmatch
(
caps
,
MIMEtype
,
key
=
'view'
,
filename
=
"/dev/null"
,
plist
=
[]):
"""Find a match for a mailcap entry.
Return a tuple containing the command line, and the mailcap entry
used; (None, None) if no match is found. This may invoke the
'test' command of several matching entries before deciding which
entry to use.
"""
entries
=
lookup
(
caps
,
MIMEtype
,
key
)
# XXX This code should somehow check for the needsterminal flag.
for
e
in
entries
:
if
e
.
has_key
(
'test'
):
test
=
subst
(
e
[
'test'
],
filename
,
plist
)
if
test
and
os
.
system
(
test
)
!=
0
:
continue
command
=
subst
(
e
[
key
],
type
,
filename
,
plist
)
command
=
subst
(
e
[
key
],
MIME
type
,
filename
,
plist
)
return
command
,
e
return
None
,
None
def
lookup
(
caps
,
type
,
key
=
None
):
def
lookup
(
caps
,
MIME
type
,
key
=
None
):
entries
=
[]
if
caps
.
has_key
(
type
):
entries
=
entries
+
caps
[
type
]
types
=
string
.
splitfields
(
type
,
'/'
)
type
=
types
[
0
]
+
'/*'
if
caps
.
has_key
(
type
):
entries
=
entries
+
caps
[
type
]
if
caps
.
has_key
(
MIME
type
):
entries
=
entries
+
caps
[
MIME
type
]
MIMEtypes
=
string
.
splitfields
(
MIME
type
,
'/'
)
MIMEtype
=
MIME
types
[
0
]
+
'/*'
if
caps
.
has_key
(
MIME
type
):
entries
=
entries
+
caps
[
MIME
type
]
if
key
is
not
None
:
entries
=
filter
(
lambda
e
,
key
=
key
:
e
.
has_key
(
key
),
entries
)
return
entries
def
subst
(
field
,
type
,
filename
,
plist
=
[]):
def
subst
(
field
,
MIME
type
,
filename
,
plist
=
[]):
# XXX Actually, this is Unix-specific
res
=
''
i
,
n
=
0
,
len
(
field
)
...
...
@@ -152,7 +167,7 @@ def subst(field, type, filename, plist=[]):
elif
c
==
's'
:
res
=
res
+
filename
elif
c
==
't'
:
res
=
res
+
type
res
=
res
+
MIME
type
elif
c
==
'{'
:
start
=
i
while
i
<
n
and
field
[
i
]
<>
'}'
:
...
...
@@ -187,11 +202,11 @@ def test():
for
i
in
range
(
1
,
len
(
sys
.
argv
),
2
):
args
=
sys
.
argv
[
i
:
i
+
2
]
if
len
(
args
)
<
2
:
print
"usage: mailcap [type file] ..."
print
"usage: mailcap [
MIME
type file] ..."
return
type
=
args
[
0
]
MIME
type
=
args
[
0
]
file
=
args
[
1
]
command
,
e
=
findmatch
(
caps
,
type
,
'view'
,
file
)
command
,
e
=
findmatch
(
caps
,
MIME
type
,
'view'
,
file
)
if
not
command
:
print
"No viewer found for"
,
type
else
:
...
...
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