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
56835dd9
Kaydet (Commit)
56835dd9
authored
22 years ago
tarafından
Barry Warsaw
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use True/False everywhere.
üst
5932c9be
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
20 deletions
+19
-20
Generator.py
Lib/email/Generator.py
+19
-20
No files found.
Lib/email/Generator.py
Dosyayı görüntüle @
56835dd9
...
...
@@ -18,6 +18,11 @@ try:
except
SyntaxError
:
from
email._compat21
import
_isstring
try
:
True
,
False
except
NameError
:
True
=
1
False
=
0
EMPTYSTRING
=
''
SEMISPACE
=
'; '
...
...
@@ -42,14 +47,15 @@ class Generator:
# Public interface
#
def
__init__
(
self
,
outfp
,
mangle_from_
=
1
,
maxheaderlen
=
78
):
def
__init__
(
self
,
outfp
,
mangle_from_
=
True
,
maxheaderlen
=
78
):
"""Create the generator for message flattening.
outfp is the output file-like object for writing the message to. It
must have a write() method.
Optional mangle_from_ is a flag that, when true, escapes From_ lines
in the body of the message by putting a `>' in front of them.
Optional mangle_from_ is a flag that, when True (the default), escapes
From_ lines in the body of the message by putting a `>' in front of
them.
Optional maxheaderlen specifies the longest length for a non-continued
header. When a header line is longer (in characters, with tabs
...
...
@@ -61,21 +67,20 @@ class Generator:
"""
self
.
_fp
=
outfp
self
.
_mangle_from_
=
mangle_from_
self
.
__first
=
1
self
.
__maxheaderlen
=
maxheaderlen
def
write
(
self
,
s
):
# Just delegate to the file object
self
.
_fp
.
write
(
s
)
def
flatten
(
self
,
msg
,
unixfrom
=
0
):
def
flatten
(
self
,
msg
,
unixfrom
=
False
):
"""Print the message object tree rooted at msg to the output file
specified when the Generator instance was created.
unixfrom is a flag that forces the printing of a Unix From_ delimiter
before the first object in the message tree. If the original message
has no From_ delimiter, a `standard' one is crafted. By default, this
is
0
to inhibit the printing of any From_ delimiter.
is
False
to inhibit the printing of any From_ delimiter.
Note that for subobjects, no From_ line is printed.
"""
...
...
@@ -146,23 +151,17 @@ class Generator:
def
_write_headers
(
self
,
msg
):
for
h
,
v
in
msg
.
items
():
# We only write the MIME-Version: header for the outermost
# container message. Unfortunately, we can't use same technique
# as for the Unix-From above because we don't know when
# MIME-Version: will occur.
if
h
.
lower
()
==
'mime-version'
and
not
self
.
__first
:
continue
# RFC 2822 says that lines SHOULD be no more than maxheaderlen
# characters wide, so we're well within our rights to split long
# headers.
text
=
'
%
s:
%
s'
%
(
h
,
v
)
if
self
.
__maxheaderlen
>
0
and
len
(
text
)
>
self
.
__maxheaderlen
:
text
=
self
.
_split_header
(
h
,
text
)
text
=
self
.
_split_header
(
text
)
print
>>
self
.
_fp
,
text
# A blank line always separates headers from body
print
>>
self
.
_fp
def
_split_header
(
self
,
name
,
text
):
def
_split_header
(
self
,
text
):
maxheaderlen
=
self
.
__maxheaderlen
# Find out whether any lines in the header are really longer than
# maxheaderlen characters wide. There could be continuation lines
...
...
@@ -225,7 +224,7 @@ class Generator:
for
part
in
subparts
:
s
=
StringIO
()
g
=
self
.
clone
(
s
)
g
.
flatten
(
part
,
unixfrom
=
0
)
g
.
flatten
(
part
,
unixfrom
=
False
)
msgtexts
.
append
(
s
.
getvalue
())
# Now make sure the boundary we've selected doesn't appear in any of
# the message texts.
...
...
@@ -264,7 +263,7 @@ class Generator:
for
part
in
msg
.
get_payload
():
s
=
StringIO
()
g
=
self
.
clone
(
s
)
g
.
flatten
(
part
,
unixfrom
=
0
)
g
.
flatten
(
part
,
unixfrom
=
False
)
text
=
s
.
getvalue
()
lines
=
text
.
split
(
'
\n
'
)
# Strip off the unnecessary trailing empty line
...
...
@@ -284,7 +283,7 @@ class Generator:
# of length 1. The zeroth element of the list should be the Message
# object for the subpart. Extract that object, stringify it, and
# write it out.
g
.
flatten
(
msg
.
get_payload
(
0
),
unixfrom
=
0
)
g
.
flatten
(
msg
.
get_payload
(
0
),
unixfrom
=
False
)
self
.
_fp
.
write
(
s
.
getvalue
())
...
...
@@ -295,7 +294,7 @@ class DecodedGenerator(Generator):
Like the Generator base class, except that non-text parts are substituted
with a format string representing the part.
"""
def
__init__
(
self
,
outfp
,
mangle_from_
=
1
,
maxheaderlen
=
78
,
fmt
=
None
):
def
__init__
(
self
,
outfp
,
mangle_from_
=
True
,
maxheaderlen
=
78
,
fmt
=
None
):
"""Like Generator.__init__() except that an additional optional
argument is allowed.
...
...
@@ -327,7 +326,7 @@ class DecodedGenerator(Generator):
for
part
in
msg
.
walk
():
maintype
=
part
.
get_main_type
(
'text'
)
if
maintype
==
'text'
:
print
>>
self
,
part
.
get_payload
(
decode
=
1
)
print
>>
self
,
part
.
get_payload
(
decode
=
True
)
elif
maintype
==
'multipart'
:
# Just skip this
pass
...
...
@@ -354,7 +353,7 @@ def _make_boundary(text=None):
return
boundary
b
=
boundary
counter
=
0
while
1
:
while
True
:
cre
=
re
.
compile
(
'^--'
+
re
.
escape
(
b
)
+
'(--)?$'
,
re
.
MULTILINE
)
if
not
cre
.
search
(
text
):
break
...
...
This diff is collapsed.
Click to expand it.
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