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

Skip to content

Commit 06fa042

Browse files
committed
Test cases and fixes for bugs described in patch #873418: email/Message.py:
del_param fails when specifying a header.
1 parent d4ff206 commit 06fa042

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

Lib/email/Message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def del_param(self, param, header='content-type', requote=True):
664664
if not self.has_key(header):
665665
return
666666
new_ctype = ''
667-
for p, v in self.get_params(header, unquote=requote):
667+
for p, v in self.get_params(header=header, unquote=requote):
668668
if p.lower() <> param.lower():
669669
if not new_ctype:
670670
new_ctype = _formatparam(p, v, requote)
@@ -700,7 +700,7 @@ def set_type(self, type, header='Content-Type', requote=True):
700700
if not self.has_key(header):
701701
self[header] = type
702702
return
703-
params = self.get_params(header, unquote=requote)
703+
params = self.get_params(header=header, unquote=requote)
704704
del self[header]
705705
self[header] = type
706706
# Skip the first param; it's the old type.

Lib/email/test/test_email.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ def test_del_param(self):
354354
('boundary', 'D1690A7AC1.996856090/mail.example.com'),
355355
('report-type', old_val)])
356356

357+
def test_del_param_on_other_header(self):
358+
msg = Message()
359+
msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')
360+
msg.del_param('filename', 'content-disposition')
361+
self.assertEqual(msg['content-disposition'], 'attachment')
362+
357363
def test_set_type(self):
358364
eq = self.assertEqual
359365
msg = Message()
@@ -365,6 +371,12 @@ def test_set_type(self):
365371
msg.set_type('text/html')
366372
eq(msg['content-type'], 'text/html; charset="us-ascii"')
367373

374+
def test_set_type_on_other_header(self):
375+
msg = Message()
376+
msg['X-Content-Type'] = 'text/plain'
377+
msg.set_type('application/octet-stream', 'X-Content-Type')
378+
self.assertEqual(msg['x-content-type'], 'application/octet-stream')
379+
368380
def test_get_content_type_missing(self):
369381
msg = Message()
370382
self.assertEqual(msg.get_content_type(), 'text/plain')

0 commit comments

Comments
 (0)