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
2c685066
Kaydet (Commit)
2c685066
authored
Haz 02, 2002
tarafından
Barry Warsaw
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Generator.__call__() => Generator.flatten()
Also, adjust to the new message/rfc822 tree layout.
üst
d2b2e533
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
28 deletions
+56
-28
test_email.py
Lib/test/test_email.py
+56
-28
No files found.
Lib/test/test_email.py
Dosyayı görüntüle @
2c685066
...
@@ -7,7 +7,7 @@ import time
...
@@ -7,7 +7,7 @@ import time
import
unittest
import
unittest
import
base64
import
base64
from
cStringIO
import
StringIO
from
cStringIO
import
StringIO
from
types
import
StringType
from
types
import
StringType
,
ListType
import
warnings
import
warnings
import
email
import
email
...
@@ -191,7 +191,7 @@ class TestMessageAPI(TestEmailBase):
...
@@ -191,7 +191,7 @@ class TestMessageAPI(TestEmailBase):
fp
.
close
()
fp
.
close
()
s
=
StringIO
()
s
=
StringIO
()
g
=
DecodedGenerator
(
s
)
g
=
DecodedGenerator
(
s
)
g
(
msg
)
g
.
flatten
(
msg
)
eq
(
s
.
getvalue
(),
text
)
eq
(
s
.
getvalue
(),
text
)
def
test__contains__
(
self
):
def
test__contains__
(
self
):
...
@@ -403,7 +403,7 @@ class TestLongHeaders(unittest.TestCase):
...
@@ -403,7 +403,7 @@ class TestLongHeaders(unittest.TestCase):
'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"'
)
'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"'
)
sfp
=
StringIO
()
sfp
=
StringIO
()
g
=
Generator
(
sfp
)
g
=
Generator
(
sfp
)
g
(
msg
)
g
.
flatten
(
msg
)
self
.
assertEqual
(
sfp
.
getvalue
(),
'''
\
self
.
assertEqual
(
sfp
.
getvalue
(),
'''
\
Content-Type: text/plain; charset="us-ascii"
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
MIME-Version: 1.0
...
@@ -423,7 +423,7 @@ X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
...
@@ -423,7 +423,7 @@ X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
msg
.
set_payload
(
'Test'
)
msg
.
set_payload
(
'Test'
)
sfp
=
StringIO
()
sfp
=
StringIO
()
g
=
Generator
(
sfp
)
g
=
Generator
(
sfp
)
g
(
msg
)
g
.
flatten
(
msg
)
self
.
assertEqual
(
sfp
.
getvalue
(),
"""
\
self
.
assertEqual
(
sfp
.
getvalue
(),
"""
\
From: test@dom.ain
From: test@dom.ain
References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
...
@@ -439,7 +439,7 @@ Test""")
...
@@ -439,7 +439,7 @@ Test""")
msg
.
set_payload
(
'Test'
)
msg
.
set_payload
(
'Test'
)
sfp
=
StringIO
()
sfp
=
StringIO
()
g
=
Generator
(
sfp
)
g
=
Generator
(
sfp
)
g
(
msg
)
g
.
flatten
(
msg
)
self
.
assertEqual
(
sfp
.
getvalue
(),
"""
\
self
.
assertEqual
(
sfp
.
getvalue
(),
"""
\
From: test@dom.ain
From: test@dom.ain
References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
...
@@ -477,7 +477,7 @@ class TestFromMangling(unittest.TestCase):
...
@@ -477,7 +477,7 @@ class TestFromMangling(unittest.TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
msg
=
Message
()
self
.
msg
=
Message
()
self
.
msg
[
'From'
]
=
'aaa@bbb.org'
self
.
msg
[
'From'
]
=
'aaa@bbb.org'
self
.
msg
.
add
_payload
(
"""
\
self
.
msg
.
set
_payload
(
"""
\
From the desk of A.A.A.:
From the desk of A.A.A.:
Blah blah blah
Blah blah blah
"""
)
"""
)
...
@@ -485,7 +485,7 @@ Blah blah blah
...
@@ -485,7 +485,7 @@ Blah blah blah
def
test_mangled_from
(
self
):
def
test_mangled_from
(
self
):
s
=
StringIO
()
s
=
StringIO
()
g
=
Generator
(
s
,
mangle_from_
=
1
)
g
=
Generator
(
s
,
mangle_from_
=
1
)
g
(
self
.
msg
)
g
.
flatten
(
self
.
msg
)
self
.
assertEqual
(
s
.
getvalue
(),
"""
\
self
.
assertEqual
(
s
.
getvalue
(),
"""
\
From: aaa@bbb.org
From: aaa@bbb.org
...
@@ -496,7 +496,7 @@ Blah blah blah
...
@@ -496,7 +496,7 @@ Blah blah blah
def
test_dont_mangle_from
(
self
):
def
test_dont_mangle_from
(
self
):
s
=
StringIO
()
s
=
StringIO
()
g
=
Generator
(
s
,
mangle_from_
=
0
)
g
=
Generator
(
s
,
mangle_from_
=
0
)
g
(
self
.
msg
)
g
.
flatten
(
self
.
msg
)
self
.
assertEqual
(
s
.
getvalue
(),
"""
\
self
.
assertEqual
(
s
.
getvalue
(),
"""
\
From: aaa@bbb.org
From: aaa@bbb.org
...
@@ -658,8 +658,8 @@ Hi there,
...
@@ -658,8 +658,8 @@ Hi there,
This is the dingus fish.
This is the dingus fish.
'''
)
'''
)
container
.
a
dd_payload
(
intro
)
container
.
a
ttach
(
intro
)
container
.
a
dd_payload
(
image
)
container
.
a
ttach
(
image
)
container
[
'From'
]
=
'Barry <barry@digicool.com>'
container
[
'From'
]
=
'Barry <barry@digicool.com>'
container
[
'To'
]
=
'Dingus Lovers <cravindogs@cravindogs.com>'
container
[
'To'
]
=
'Dingus Lovers <cravindogs@cravindogs.com>'
container
[
'Subject'
]
=
'Here is your dingus fish'
container
[
'Subject'
]
=
'Here is your dingus fish'
...
@@ -851,24 +851,38 @@ class TestMIMEMessage(TestEmailBase):
...
@@ -851,24 +851,38 @@ class TestMIMEMessage(TestEmailBase):
def
test_valid_argument
(
self
):
def
test_valid_argument
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
unless
=
self
.
failUnless
subject
=
'A sub-message'
subject
=
'A sub-message'
m
=
Message
()
m
=
Message
()
m
[
'Subject'
]
=
subject
m
[
'Subject'
]
=
subject
r
=
MIMEMessage
(
m
)
r
=
MIMEMessage
(
m
)
eq
(
r
.
get_type
(),
'message/rfc822'
)
eq
(
r
.
get_type
(),
'message/rfc822'
)
self
.
failUnless
(
r
.
get_payload
()
is
m
)
payload
=
r
.
get_payload
()
eq
(
r
.
get_payload
()[
'subject'
],
subject
)
unless
(
type
(
payload
),
ListType
)
eq
(
len
(
payload
),
1
)
subpart
=
payload
[
0
]
unless
(
subpart
is
m
)
eq
(
subpart
[
'subject'
],
subject
)
def
test_bad_multipart
(
self
):
eq
=
self
.
assertEqual
msg1
=
Message
()
msg1
[
'Subject'
]
=
'subpart 1'
msg2
=
Message
()
msg2
[
'Subject'
]
=
'subpart 2'
r
=
MIMEMessage
(
msg1
)
self
.
assertRaises
(
Errors
.
MultipartConversionError
,
r
.
attach
,
msg2
)
def
test_generate
(
self
):
def
test_generate
(
self
):
# First craft the message to be encapsulated
# First craft the message to be encapsulated
m
=
Message
()
m
=
Message
()
m
[
'Subject'
]
=
'An enclosed message'
m
[
'Subject'
]
=
'An enclosed message'
m
.
add
_payload
(
'Here is the body of the message.
\n
'
)
m
.
set
_payload
(
'Here is the body of the message.
\n
'
)
r
=
MIMEMessage
(
m
)
r
=
MIMEMessage
(
m
)
r
[
'Subject'
]
=
'The enclosing message'
r
[
'Subject'
]
=
'The enclosing message'
s
=
StringIO
()
s
=
StringIO
()
g
=
Generator
(
s
)
g
=
Generator
(
s
)
g
(
r
)
g
.
flatten
(
r
)
self
.
assertEqual
(
s
.
getvalue
(),
"""
\
self
.
assertEqual
(
s
.
getvalue
(),
"""
\
Content-Type: message/rfc822
Content-Type: message/rfc822
MIME-Version: 1.0
MIME-Version: 1.0
...
@@ -881,10 +895,13 @@ Here is the body of the message.
...
@@ -881,10 +895,13 @@ Here is the body of the message.
def
test_parse_message_rfc822
(
self
):
def
test_parse_message_rfc822
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
unless
=
self
.
failUnless
msg
=
self
.
_msgobj
(
'msg_11.txt'
)
msg
=
self
.
_msgobj
(
'msg_11.txt'
)
eq
(
msg
.
get_type
(),
'message/rfc822'
)
eq
(
msg
.
get_type
(),
'message/rfc822'
)
eq
(
len
(
msg
.
get_payload
()),
1
)
payload
=
msg
.
get_payload
()
submsg
=
msg
.
get_payload
()
unless
(
isinstance
(
payload
,
ListType
))
eq
(
len
(
payload
),
1
)
submsg
=
payload
[
0
]
self
.
failUnless
(
isinstance
(
submsg
,
Message
))
self
.
failUnless
(
isinstance
(
submsg
,
Message
))
eq
(
submsg
[
'subject'
],
'An enclosed message'
)
eq
(
submsg
[
'subject'
],
'An enclosed message'
)
eq
(
submsg
.
get_payload
(),
'Here is the body of the message.
\n
'
)
eq
(
submsg
.
get_payload
(),
'Here is the body of the message.
\n
'
)
...
@@ -938,7 +955,10 @@ Your message cannot be delivered to the following recipients:
...
@@ -938,7 +955,10 @@ Your message cannot be delivered to the following recipients:
# Subpart 3 is the original message
# Subpart 3 is the original message
subpart
=
msg
.
get_payload
(
2
)
subpart
=
msg
.
get_payload
(
2
)
eq
(
subpart
.
get_type
(),
'message/rfc822'
)
eq
(
subpart
.
get_type
(),
'message/rfc822'
)
subsubpart
=
subpart
.
get_payload
()
payload
=
subpart
.
get_payload
()
unless
(
isinstance
(
payload
,
ListType
))
eq
(
len
(
payload
),
1
)
subsubpart
=
payload
[
0
]
unless
(
isinstance
(
subsubpart
,
Message
))
unless
(
isinstance
(
subsubpart
,
Message
))
eq
(
subsubpart
.
get_type
(),
'text/plain'
)
eq
(
subsubpart
.
get_type
(),
'text/plain'
)
eq
(
subsubpart
[
'message-id'
],
eq
(
subsubpart
[
'message-id'
],
...
@@ -959,11 +979,11 @@ Your message cannot be delivered to the following recipients:
...
@@ -959,11 +979,11 @@ Your message cannot be delivered to the following recipients:
msg1
=
MIMEText
(
'One'
)
msg1
=
MIMEText
(
'One'
)
msg2
=
MIMEText
(
'Two'
)
msg2
=
MIMEText
(
'Two'
)
msg
.
add_header
(
'Content-Type'
,
'multipart/mixed'
,
boundary
=
'BOUNDARY'
)
msg
.
add_header
(
'Content-Type'
,
'multipart/mixed'
,
boundary
=
'BOUNDARY'
)
msg
.
a
dd_payload
(
msg1
)
msg
.
a
ttach
(
msg1
)
msg
.
a
dd_payload
(
msg2
)
msg
.
a
ttach
(
msg2
)
sfp
=
StringIO
()
sfp
=
StringIO
()
g
=
Generator
(
sfp
)
g
=
Generator
(
sfp
)
g
(
msg
)
g
.
flatten
(
msg
)
self
.
assertEqual
(
sfp
.
getvalue
(),
text
)
self
.
assertEqual
(
sfp
.
getvalue
(),
text
)
...
@@ -987,7 +1007,7 @@ class TestIdempotent(unittest.TestCase):
...
@@ -987,7 +1007,7 @@ class TestIdempotent(unittest.TestCase):
eq
=
self
.
assertEquals
eq
=
self
.
assertEquals
s
=
StringIO
()
s
=
StringIO
()
g
=
Generator
(
s
,
maxheaderlen
=
0
)
g
=
Generator
(
s
,
maxheaderlen
=
0
)
g
(
msg
)
g
.
flatten
(
msg
)
eq
(
text
,
s
.
getvalue
())
eq
(
text
,
s
.
getvalue
())
def
test_parse_text_message
(
self
):
def
test_parse_text_message
(
self
):
...
@@ -1044,6 +1064,7 @@ class TestIdempotent(unittest.TestCase):
...
@@ -1044,6 +1064,7 @@ class TestIdempotent(unittest.TestCase):
def
test_content_type
(
self
):
def
test_content_type
(
self
):
eq
=
self
.
assertEquals
eq
=
self
.
assertEquals
unless
=
self
.
failUnless
# Get a message object and reset the seek pointer for other tests
# Get a message object and reset the seek pointer for other tests
msg
,
text
=
self
.
_msgobj
(
'msg_05.txt'
)
msg
,
text
=
self
.
_msgobj
(
'msg_05.txt'
)
eq
(
msg
.
get_type
(),
'multipart/report'
)
eq
(
msg
.
get_type
(),
'multipart/report'
)
...
@@ -1066,18 +1087,25 @@ class TestIdempotent(unittest.TestCase):
...
@@ -1066,18 +1087,25 @@ class TestIdempotent(unittest.TestCase):
msg3
=
msg
.
get_payload
(
2
)
msg3
=
msg
.
get_payload
(
2
)
eq
(
msg3
.
get_type
(),
'message/rfc822'
)
eq
(
msg3
.
get_type
(),
'message/rfc822'
)
self
.
failUnless
(
isinstance
(
msg3
,
Message
))
self
.
failUnless
(
isinstance
(
msg3
,
Message
))
msg4
=
msg3
.
get_payload
()
payload
=
msg3
.
get_payload
()
self
.
failUnless
(
isinstance
(
msg4
,
Message
))
unless
(
isinstance
(
payload
,
ListType
))
eq
(
len
(
payload
),
1
)
msg4
=
payload
[
0
]
unless
(
isinstance
(
msg4
,
Message
))
eq
(
msg4
.
get_payload
(),
'Yadda yadda yadda
\n
'
)
eq
(
msg4
.
get_payload
(),
'Yadda yadda yadda
\n
'
)
def
test_parser
(
self
):
def
test_parser
(
self
):
eq
=
self
.
assertEquals
eq
=
self
.
assertEquals
unless
=
self
.
failUnless
msg
,
text
=
self
.
_msgobj
(
'msg_06.txt'
)
msg
,
text
=
self
.
_msgobj
(
'msg_06.txt'
)
# Check some of the outer headers
# Check some of the outer headers
eq
(
msg
.
get_type
(),
'message/rfc822'
)
eq
(
msg
.
get_type
(),
'message/rfc822'
)
# Make sure there's exactly one thing in the payload and that's a
# Make sure the payload is a list of exactly one sub-Message, and that
# sub-Message object of type text/plain
# that submessage has a type of text/plain
msg1
=
msg
.
get_payload
()
payload
=
msg
.
get_payload
()
unless
(
isinstance
(
payload
,
ListType
))
eq
(
len
(
payload
),
1
)
msg1
=
payload
[
0
]
self
.
failUnless
(
isinstance
(
msg1
,
Message
))
self
.
failUnless
(
isinstance
(
msg1
,
Message
))
eq
(
msg1
.
get_type
(),
'text/plain'
)
eq
(
msg1
.
get_type
(),
'text/plain'
)
self
.
failUnless
(
isinstance
(
msg1
.
get_payload
(),
StringType
))
self
.
failUnless
(
isinstance
(
msg1
.
get_payload
(),
StringType
))
...
@@ -1097,7 +1125,7 @@ class TestMiscellaneous(unittest.TestCase):
...
@@ -1097,7 +1125,7 @@ class TestMiscellaneous(unittest.TestCase):
# Don't wrap/continue long headers since we're trying to test
# Don't wrap/continue long headers since we're trying to test
# idempotency.
# idempotency.
g
=
Generator
(
s
,
maxheaderlen
=
0
)
g
=
Generator
(
s
,
maxheaderlen
=
0
)
g
(
msg
)
g
.
flatten
(
msg
)
self
.
assertEqual
(
text
,
s
.
getvalue
())
self
.
assertEqual
(
text
,
s
.
getvalue
())
def
test_message_from_file
(
self
):
def
test_message_from_file
(
self
):
...
@@ -1110,7 +1138,7 @@ class TestMiscellaneous(unittest.TestCase):
...
@@ -1110,7 +1138,7 @@ class TestMiscellaneous(unittest.TestCase):
# Don't wrap/continue long headers since we're trying to test
# Don't wrap/continue long headers since we're trying to test
# idempotency.
# idempotency.
g
=
Generator
(
s
,
maxheaderlen
=
0
)
g
=
Generator
(
s
,
maxheaderlen
=
0
)
g
(
msg
)
g
.
flatten
(
msg
)
self
.
assertEqual
(
text
,
s
.
getvalue
())
self
.
assertEqual
(
text
,
s
.
getvalue
())
finally
:
finally
:
fp
.
close
()
fp
.
close
()
...
...
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