Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc74e34

Browse files
committed
Resolve SF bug 1409403: email.Message should supress warning from uu.decode.
However, the patch in that tracker item is elaborated such that the newlyincluded unit test pass on Python 2.1 through 2.5. Note that Python 2.1'suu.decode() does not have a 'quiet' argument, so we have to be sneaky.Will port to email 3.0 (although without the backward compatible sneakiness).
1 parentf5853f7 commitdc74e34

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

‎Lib/email/Message.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
True=1
2424
False=0
2525

26+
try:
27+
fromemail._compat22importquiet_uu_decode
28+
exceptSyntaxError:
29+
fromemail._compat21importquiet_uu_decode
30+
31+
2632
# Regular expression used to split header parameters. BAW: this may be too
2733
# simple. It isn't strictly RFC 2045 (section 5.1) compliant, but it catches
2834
# most headers found in the wild. We may eventually need a full fledged
@@ -220,7 +226,7 @@ def get_payload(self, i=None, decode=False):
220226
elifctein ('x-uuencode','uuencode','uue','x-uue'):
221227
sfp=StringIO()
222228
try:
223-
uu.decode(StringIO(payload+'\n'),sfp)
229+
quiet_uu_decode(StringIO(payload+'\n'),sfp,quiet=True)
224230
payload=sfp.getvalue()
225231
exceptuu.Error:
226232
# Some decoding problem

‎Lib/email/_compat21.py‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Copyright (C) 2002 Python Software Foundation
2-
# Author: barry@zope.com
1+
# Copyright (C) 2002-2006 Python Software Foundation
2+
# Author: barry@python.org
33

4-
"""Module containing compatibility functions for Python 2.1.
5-
"""
4+
"""Module containing compatibility functions for Python 2.1."""
5+
6+
importuu
7+
importsys
68

79
fromcStringIOimportStringIO
810
fromtypesimportStringType,UnicodeType
@@ -67,3 +69,14 @@ def typed_subpart_iterator(msg, maintype='text', subtype=None):
6769
ifsubtypeisNoneorsubpart.get_content_subtype()==subtype:
6870
parts.append(subpart)
6971
returnparts
72+
73+
74+
75+
defquiet_uu_decode(in_file,out_file,quiet):
76+
# In Python 2.1, uu.decode() does not support the quiet flag. Cheat.
77+
old_stderr=sys.stderr
78+
try:
79+
sys.stderr=StringIO()
80+
uu.decode(in_file,out_file)
81+
finally:
82+
sys.stderr=old_stderr

‎Lib/email/_compat22.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
# Copyright (C) 2002 Python Software Foundation
2-
# Author: barry@zope.com
1+
# Copyright (C) 2002-2006 Python Software Foundation
2+
# Author: barry@python.org
33

4-
"""Module containing compatibility functions for Python 2.2.
4+
"""Module containing compatibility functions for Python 2.2 (and possibly
5+
beyond.
56
"""
67

78
from __future__importgenerators
89
from __future__importdivision
910
fromcStringIOimportStringIO
1011
fromtypesimportStringTypes
1112

13+
importuu
14+
1215
# Python 2.2.x where x < 1 lacks True/False
1316
try:
1417
True,False
@@ -68,3 +71,8 @@ def typed_subpart_iterator(msg, maintype='text', subtype=None):
6871
ifsubpart.get_content_maintype()==maintype:
6972
ifsubtypeisNoneorsubpart.get_content_subtype()==subtype:
7073
yieldsubpart
74+
75+
76+
77+
defquiet_uu_decode(in_file,out_file,quiet):
78+
uu.decode(in_file,out_file,quiet=quiet)

‎Lib/email/test/test_email.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ def test_get_decoded_uu_payload(self):
222222
msg.set_payload('foo')
223223
eq(msg.get_payload(decode=True),'foo')
224224

225+
deftest_decode_bogus_uu_payload_quietly(self):
226+
msg=Message()
227+
msg.set_payload('begin 664 foo.txt\n%<W1F=0000H\n\nend\n')
228+
msg['Content-Transfer-Encoding']='x-uuencode'
229+
old_stderr=sys.stderr
230+
try:
231+
sys.stderr=sfp=StringIO()
232+
# We don't care about the payload
233+
msg.get_payload(decode=True)
234+
finally:
235+
sys.stderr=old_stderr
236+
self.assertEqual(sfp.getvalue(),'')
237+
225238
deftest_decoded_generator(self):
226239
eq=self.assertEqual
227240
msg=self._msgobj('msg_07.txt')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp