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
b17b4a4e
Kaydet (Commit)
b17b4a4e
authored
May 29, 2002
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Backport change to 1.8 adding docstrings
üst
87d63163
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
3 deletions
+56
-3
MimeWriter.py
Lib/MimeWriter.py
+56
-3
No files found.
Lib/MimeWriter.py
Dosyayı görüntüle @
b17b4a4e
"""Generic MIME writer.
"""Generic MIME writer.
Classes:
This module defines the class MimeWriter. The MimeWriter class implements
a basic formatter for creating MIME multi-part files. It doesn't seek around
MimeWriter - the only thing here.
the output file nor does it use large amounts of buffer space. You must write
the parts out in the order that they should occur in the final file.
MimeWriter does buffer the headers you add, allowing you to rearrange their
order.
"""
"""
...
@@ -86,6 +89,14 @@ class MimeWriter:
...
@@ -86,6 +89,14 @@ class MimeWriter:
self
.
_headers
=
[]
self
.
_headers
=
[]
def
addheader
(
self
,
key
,
value
,
prefix
=
0
):
def
addheader
(
self
,
key
,
value
,
prefix
=
0
):
"""Add a header line to the MIME message.
The key is the name of the header, where the value obviously provides
the value of the header. The optional argument prefix determines
where the header is inserted; 0 means append at the end, 1 means
insert at the start. The default is to append.
"""
lines
=
value
.
split
(
"
\n
"
)
lines
=
value
.
split
(
"
\n
"
)
while
lines
and
not
lines
[
-
1
]:
del
lines
[
-
1
]
while
lines
and
not
lines
[
-
1
]:
del
lines
[
-
1
]
while
lines
and
not
lines
[
0
]:
del
lines
[
0
]
while
lines
and
not
lines
[
0
]:
del
lines
[
0
]
...
@@ -99,10 +110,26 @@ class MimeWriter:
...
@@ -99,10 +110,26 @@ class MimeWriter:
self
.
_headers
.
append
(
line
)
self
.
_headers
.
append
(
line
)
def
flushheaders
(
self
):
def
flushheaders
(
self
):
"""Writes out and forgets all headers accumulated so far.
This is useful if you don't need a body part at all; for example,
for a subpart of type message/rfc822 that's (mis)used to store some
header-like information.
"""
self
.
_fp
.
writelines
(
self
.
_headers
)
self
.
_fp
.
writelines
(
self
.
_headers
)
self
.
_headers
=
[]
self
.
_headers
=
[]
def
startbody
(
self
,
ctype
,
plist
=
[],
prefix
=
1
):
def
startbody
(
self
,
ctype
,
plist
=
[],
prefix
=
1
):
"""Returns a file-like object for writing the body of the message.
The content-type is set to the provided ctype, and the optional
parameter, plist, provides additional parameters for the
content-type declaration. The optional argument prefix determines
where the header is inserted; 0 means append at the end, 1 means
insert at the start. The default is to insert at the start.
"""
for
name
,
value
in
plist
:
for
name
,
value
in
plist
:
ctype
=
ctype
+
';
\n
%
s=
\"
%
s
\"
'
%
(
name
,
value
)
ctype
=
ctype
+
';
\n
%
s=
\"
%
s
\"
'
%
(
name
,
value
)
self
.
addheader
(
"Content-Type"
,
ctype
,
prefix
=
prefix
)
self
.
addheader
(
"Content-Type"
,
ctype
,
prefix
=
prefix
)
...
@@ -111,16 +138,42 @@ class MimeWriter:
...
@@ -111,16 +138,42 @@ class MimeWriter:
return
self
.
_fp
return
self
.
_fp
def
startmultipartbody
(
self
,
subtype
,
boundary
=
None
,
plist
=
[],
prefix
=
1
):
def
startmultipartbody
(
self
,
subtype
,
boundary
=
None
,
plist
=
[],
prefix
=
1
):
"""Returns a file-like object for writing the body of the message.
Additionally, this method initializes the multi-part code, where the
subtype parameter provides the multipart subtype, the boundary
parameter may provide a user-defined boundary specification, and the
plist parameter provides optional parameters for the subtype. The
optional argument, prefix, determines where the header is inserted;
0 means append at the end, 1 means insert at the start. The default
is to insert at the start. Subparts should be created using the
nextpart() method.
"""
self
.
_boundary
=
boundary
or
mimetools
.
choose_boundary
()
self
.
_boundary
=
boundary
or
mimetools
.
choose_boundary
()
return
self
.
startbody
(
"multipart/"
+
subtype
,
return
self
.
startbody
(
"multipart/"
+
subtype
,
[(
"boundary"
,
self
.
_boundary
)]
+
plist
,
[(
"boundary"
,
self
.
_boundary
)]
+
plist
,
prefix
=
prefix
)
prefix
=
prefix
)
def
nextpart
(
self
):
def
nextpart
(
self
):
"""Returns a new instance of MimeWriter which represents an
individual part in a multipart message.
This may be used to write the part as well as used for creating
recursively complex multipart messages. The message must first be
initialized with the startmultipartbody() method before using the
nextpart() method.
"""
self
.
_fp
.
write
(
"
\n
--"
+
self
.
_boundary
+
"
\n
"
)
self
.
_fp
.
write
(
"
\n
--"
+
self
.
_boundary
+
"
\n
"
)
return
self
.
__class__
(
self
.
_fp
)
return
self
.
__class__
(
self
.
_fp
)
def
lastpart
(
self
):
def
lastpart
(
self
):
"""This is used to designate the last part of a multipart message.
It should always be used when writing multipart messages.
"""
self
.
_fp
.
write
(
"
\n
--"
+
self
.
_boundary
+
"--
\n
"
)
self
.
_fp
.
write
(
"
\n
--"
+
self
.
_boundary
+
"--
\n
"
)
...
...
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