Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7aa02e6

Browse files
committed
More email package fixes.
Fix a couple of tests since .body_encode()'s arguments have changed. Also, I think body_encode() should take a string not a byte array for consistency with the rest of the api (but I'm not positive about this). In quoprimime.body_encode(), body_check() must be passed an int. Current status: 7F (no errors!)
1 parent 0616b79 commit 7aa02e6

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

Lib/email/quoprimime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def body_encode(body, maxlinelen=76, eol=NL):
189189
for j in range(linelen):
190190
c = line[j]
191191
prev = c
192-
if body_check(c):
192+
if body_check(ord(c)):
193193
c = quote(c)
194194
elif j+1 == linelen:
195195
# Check for whitespace at end of line; special case

Lib/email/test/test_email.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,6 @@ def test_encode(self):
25552555
eq(base64mime.body_encode('hello'), 'aGVsbG8=\n')
25562556
# Test the binary flag
25572557
eq(base64mime.body_encode('hello\n'), 'aGVsbG8K\n')
2558-
eq(base64mime.body_encode('hello\n', 0), 'aGVsbG8NCg==\n')
25592558
# Test the maxlinelen arg
25602559
eq(base64mime.body_encode('xxxx ' * 20, maxlinelen=40), """\
25612560
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
@@ -2564,7 +2563,8 @@ def test_encode(self):
25642563
eHh4eCB4eHh4IA==
25652564
""")
25662565
# Test the eol argument
2567-
eq(base64mime.encode('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
2566+
eq(base64mime.body_encode('xxxx ' * 20, maxlinelen=40, eol='\r\n'),
2567+
"""\
25682568
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
25692569
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
25702570
eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
@@ -2681,7 +2681,6 @@ def test_encode(self):
26812681
eq(quoprimime.body_encode('hello'), 'hello')
26822682
# Test the binary flag
26832683
eq(quoprimime.body_encode('hello\r\nworld'), 'hello\nworld')
2684-
eq(quoprimime.body_encode('hello\r\nworld', 0), 'hello\nworld')
26852684
# Test the maxlinelen arg
26862685
eq(quoprimime.body_encode('xxxx ' * 20, maxlinelen=40), """\
26872686
xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
@@ -2727,21 +2726,21 @@ def test_body_encode(self):
27272726
eq = self.assertEqual
27282727
# Try a charset with QP body encoding
27292728
c = Charset('iso-8859-1')
2730-
eq('hello w=F6rld', c.body_encode(b'hello w\xf6rld'))
2729+
eq('hello w=F6rld', c.body_encode('hello w\xf6rld'))
27312730
# Try a charset with Base64 body encoding
27322731
c = Charset('utf-8')
2733-
eq('aGVsbG8gd29ybGQ=\n', c.body_encode(b'hello world'))
2732+
eq('aGVsbG8gd29ybGQ=\n', c.body_encode('hello world'))
27342733
# Try a charset with None body encoding
27352734
c = Charset('us-ascii')
2736-
eq('hello world', c.body_encode(b'hello world'))
2735+
eq('hello world', c.body_encode('hello world'))
27372736
# Try the convert argument, where input codec != output codec
27382737
c = Charset('euc-jp')
27392738
# With apologies to Tokio Kikuchi ;)
27402739
try:
27412740
eq('\x1b$B5FCO;~IW\x1b(B',
2742-
c.body_encode(b'\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7'))
2741+
c.body_encode('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7'))
27432742
eq('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7',
2744-
c.body_encode(b'\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7', False))
2743+
c.body_encode('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7', False))
27452744
except LookupError:
27462745
# We probably don't have the Japanese codecs installed
27472746
pass
@@ -2751,7 +2750,7 @@ def test_body_encode(self):
27512750
from email import charset as CharsetModule
27522751
CharsetModule.add_charset('fake', CharsetModule.QP, None)
27532752
c = Charset('fake')
2754-
eq('hello w\xf6rld', c.body_encode(b'hello w\xf6rld'))
2753+
eq('hello w\xf6rld', c.body_encode('hello w\xf6rld'))
27552754

27562755
def test_unicode_charset_name(self):
27572756
charset = Charset('us-ascii')

0 commit comments

Comments
 (0)