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

Skip to content

Commit d20b665

Browse files
committed
The ansi_x3.4_1968 encoding is an alias for ascii, but isn't known in
Python 2.1.3. However it's required by the email tests suite, so poke it into the encodings aliases if it's missing. The is apparently the approved API for doing so. Now we can remove the hexversion shortcircuits in the test suite.
1 parent a2a07bc commit d20b665

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

Lib/email/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,12 @@ def message_from_file(fp, _class=None, strict=False):
5959
from email.Message import Message
6060
_class = Message
6161
return Parser(_class, strict=strict).parse(fp)
62+
63+
64+
65+
# Patch encodings.aliases to recognize 'ansi_x3.4_1968' which isn't a standard
66+
# alias in Python 2.1.3, but is used by the email package test suite.
67+
from encodings.aliases import aliases # The aliases dictionary
68+
if not aliases.has_key('ansi_x3.4_1968'):
69+
aliases['ansi_x3.4_1968'] = 'ascii'
70+
del aliases # Not needed any more

Lib/email/test/test_email.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,12 +1470,6 @@ def test_rfc2231_charset(self):
14701470
self._idempotent(msg, text)
14711471

14721472
def test_more_rfc2231_parameters(self):
1473-
# BAW: What to do about this. Python 2.1 doesn't know about the
1474-
# charset ansi-x3.4-1968, so this test will fail. Do we teach Python
1475-
# about that charset, and if so, where (maybe Charset.py)? For now,
1476-
# just skip this test if we aren't at least in Python 2.2.
1477-
if sys.hexversion < 0x20200000:
1478-
return
14791473
msg, text = self._msgobj('msg_33.txt')
14801474
self._idempotent(msg, text)
14811475

@@ -2258,12 +2252,6 @@ def test_del_param(self):
22582252
""")
22592253

22602254
def test_rfc2231_get_content_charset(self):
2261-
# BAW: What to do about this. Python 2.1 doesn't know about the
2262-
# charset ansi-x3.4-1968, so this test will fail. Do we teach Python
2263-
# about that charset, and if so, where (maybe Charset.py)? For now,
2264-
# just skip this test if we aren't at least in Python 2.2.
2265-
if sys.hexversion < 0x20200000:
2266-
return
22672255
eq = self.assertEqual
22682256
msg = self._msgobj('msg_32.txt')
22692257
eq(msg.get_content_charset(), 'us-ascii')

0 commit comments

Comments
 (0)