Skip to content

Commit f30efeb

Browse files
authored
Merge pull request #278 from jmgurney/fixsur
exc not defined in this function, raise the correct error...
2 parents ecf1121 + da5e6d2 commit f30efeb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/future/utils/surrogateescape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def replace_surrogate_encode(mystring):
8383
# The following magic comes from Py3.3's Python/codecs.c file:
8484
if not 0xD800 <= code <= 0xDCFF:
8585
# Not a surrogate. Fail with the original exception.
86-
raise exc
86+
raise NotASurrogateError
8787
# mybytes = [0xe0 | (code >> 12),
8888
# 0x80 | ((code >> 6) & 0x3f),
8989
# 0x80 | (code & 0x3f)]

tests/test_future/test_surrogateescape.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def test_encode_ascii_surrogateescape(self):
3333
b = payload.encode('ascii', 'surrogateescape')
3434
self.assertEqual(b, b'cMO2c3RhbA\xc3\xa1=\n')
3535

36+
def test_encode_ascii_unicode(self):
37+
"""
38+
Verify that exceptions are raised properly.
39+
"""
40+
self.assertRaises(UnicodeEncodeError, u'\N{SNOWMAN}'.encode, 'US-ASCII', 'surrogateescape')
41+
3642
@expectedFailurePY2
3743
def test_encode_ascii_surrogateescape_non_newstr(self):
3844
"""

0 commit comments

Comments
 (0)