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
b8c53709
Kaydet (Commit)
b8c53709
authored
Agu 22, 2013
tarafından
R David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge #18324: set_payload now correctly handles binary input.
üst
cba2e3c2
00ae435d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
16 deletions
+45
-16
encoders.py
Lib/email/encoders.py
+4
-16
message.py
Lib/email/message.py
+2
-0
test_email.py
Lib/test/test_email/test_email.py
+36
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/email/encoders.py
Dosyayı görüntüle @
b8c53709
...
@@ -28,7 +28,7 @@ def encode_base64(msg):
...
@@ -28,7 +28,7 @@ def encode_base64(msg):
Also, add an appropriate Content-Transfer-Encoding header.
Also, add an appropriate Content-Transfer-Encoding header.
"""
"""
orig
=
msg
.
get_payload
()
orig
=
msg
.
get_payload
(
decode
=
True
)
encdata
=
str
(
_bencode
(
orig
),
'ascii'
)
encdata
=
str
(
_bencode
(
orig
),
'ascii'
)
msg
.
set_payload
(
encdata
)
msg
.
set_payload
(
encdata
)
msg
[
'Content-Transfer-Encoding'
]
=
'base64'
msg
[
'Content-Transfer-Encoding'
]
=
'base64'
...
@@ -40,20 +40,16 @@ def encode_quopri(msg):
...
@@ -40,20 +40,16 @@ def encode_quopri(msg):
Also, add an appropriate Content-Transfer-Encoding header.
Also, add an appropriate Content-Transfer-Encoding header.
"""
"""
orig
=
msg
.
get_payload
()
orig
=
msg
.
get_payload
(
decode
=
True
)
if
isinstance
(
orig
,
str
):
# If it is a string, the model data may have binary data encoded in via
# surrogateescape. Convert back to bytes so we can CTE encode it.
orig
=
orig
.
encode
(
'ascii'
,
'surrogateescape'
)
encdata
=
_qencode
(
orig
)
encdata
=
_qencode
(
orig
)
msg
.
set_payload
(
encdata
.
decode
(
'ascii'
,
'surrogateescape'
)
)
msg
.
set_payload
(
encdata
)
msg
[
'Content-Transfer-Encoding'
]
=
'quoted-printable'
msg
[
'Content-Transfer-Encoding'
]
=
'quoted-printable'
def
encode_7or8bit
(
msg
):
def
encode_7or8bit
(
msg
):
"""Set the Content-Transfer-Encoding header to 7bit or 8bit."""
"""Set the Content-Transfer-Encoding header to 7bit or 8bit."""
orig
=
msg
.
get_payload
()
orig
=
msg
.
get_payload
(
decode
=
True
)
if
orig
is
None
:
if
orig
is
None
:
# There's no payload. For backwards compatibility we use 7bit
# There's no payload. For backwards compatibility we use 7bit
msg
[
'Content-Transfer-Encoding'
]
=
'7bit'
msg
[
'Content-Transfer-Encoding'
]
=
'7bit'
...
@@ -75,16 +71,8 @@ def encode_7or8bit(msg):
...
@@ -75,16 +71,8 @@ def encode_7or8bit(msg):
msg
[
'Content-Transfer-Encoding'
]
=
'8bit'
msg
[
'Content-Transfer-Encoding'
]
=
'8bit'
else
:
else
:
msg
[
'Content-Transfer-Encoding'
]
=
'7bit'
msg
[
'Content-Transfer-Encoding'
]
=
'7bit'
if
not
isinstance
(
orig
,
str
):
msg
.
set_payload
(
orig
.
decode
(
'ascii'
,
'surrogateescape'
))
def
encode_noop
(
msg
):
def
encode_noop
(
msg
):
"""Do nothing."""
"""Do nothing."""
# Well, not quite *nothing*: in Python3 we have to turn bytes into a string
# in our internal surrogateescaped form in order to keep the model
# consistent.
orig
=
msg
.
get_payload
()
if
not
isinstance
(
orig
,
str
):
msg
.
set_payload
(
orig
.
decode
(
'ascii'
,
'surrogateescape'
))
Lib/email/message.py
Dosyayı görüntüle @
b8c53709
...
@@ -303,6 +303,8 @@ class Message:
...
@@ -303,6 +303,8 @@ class Message:
Optional charset sets the message's default character set. See
Optional charset sets the message's default character set. See
set_charset() for details.
set_charset() for details.
"""
"""
if
isinstance
(
payload
,
bytes
):
payload
=
payload
.
decode
(
'ascii'
,
'surrogateescape'
)
self
.
_payload
=
payload
self
.
_payload
=
payload
if
charset
is
not
None
:
if
charset
is
not
None
:
self
.
set_charset
(
charset
)
self
.
set_charset
(
charset
)
...
...
Lib/test/test_email/test_email.py
Dosyayı görüntüle @
b8c53709
...
@@ -620,6 +620,42 @@ class TestMessageAPI(TestEmailBase):
...
@@ -620,6 +620,42 @@ class TestMessageAPI(TestEmailBase):
"attachment; filename*=utf-8''Fu
%
C3
%9
Fballer
%20%5
Bfilename
%5
D.ppt"
,
"attachment; filename*=utf-8''Fu
%
C3
%9
Fballer
%20%5
Bfilename
%5
D.ppt"
,
msg
[
'Content-Disposition'
])
msg
[
'Content-Disposition'
])
def
test_binary_quopri_payload
(
self
):
for
charset
in
(
'latin-1'
,
'ascii'
):
msg
=
Message
()
msg
[
'content-type'
]
=
'text/plain; charset=
%
s'
%
charset
msg
[
'content-transfer-encoding'
]
=
'quoted-printable'
msg
.
set_payload
(
b
'foo=e6=96=87bar'
)
self
.
assertEqual
(
msg
.
get_payload
(
decode
=
True
),
b
'foo
\xe6\x96\x87
bar'
,
'get_payload returns wrong result with charset
%
s.'
%
charset
)
def
test_binary_base64_payload
(
self
):
for
charset
in
(
'latin-1'
,
'ascii'
):
msg
=
Message
()
msg
[
'content-type'
]
=
'text/plain; charset=
%
s'
%
charset
msg
[
'content-transfer-encoding'
]
=
'base64'
msg
.
set_payload
(
b
'Zm9v5paHYmFy'
)
self
.
assertEqual
(
msg
.
get_payload
(
decode
=
True
),
b
'foo
\xe6\x96\x87
bar'
,
'get_payload returns wrong result with charset
%
s.'
%
charset
)
def
test_binary_uuencode_payload
(
self
):
for
charset
in
(
'latin-1'
,
'ascii'
):
for
encoding
in
(
'x-uuencode'
,
'uuencode'
,
'uue'
,
'x-uue'
):
msg
=
Message
()
msg
[
'content-type'
]
=
'text/plain; charset=
%
s'
%
charset
msg
[
'content-transfer-encoding'
]
=
encoding
msg
.
set_payload
(
b
"begin 666 -
\n
)9F]OYI:'8F
%
R
\n
\n
end
\n
"
)
self
.
assertEqual
(
msg
.
get_payload
(
decode
=
True
),
b
'foo
\xe6\x96\x87
bar'
,
str
((
'get_payload returns wrong result '
,
'with charset {0} and encoding {1}.'
))
.
\
format
(
charset
,
encoding
))
def
test_add_header_with_name_only_param
(
self
):
def
test_add_header_with_name_only_param
(
self
):
msg
=
Message
()
msg
=
Message
()
msg
.
add_header
(
'Content-Disposition'
,
'inline'
,
foo_bar
=
None
)
msg
.
add_header
(
'Content-Disposition'
,
'inline'
,
foo_bar
=
None
)
...
...
Misc/NEWS
Dosyayı görüntüle @
b8c53709
...
@@ -38,6 +38,9 @@ Core and Builtins
...
@@ -38,6 +38,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #18324: set_payload now correctly handles binary input. This also
supersedes the previous fixes for #14360, #1717, and #16564.
- Issue #18794: Add a fileno() method and a closed attribute to select.devpoll
- Issue #18794: Add a fileno() method and a closed attribute to select.devpoll
objects.
objects.
...
...
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