From da5e6d241bb6a58a5a1e2e941602037d47115781 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sun, 9 Apr 2017 00:20:51 -0700 Subject: [PATCH] exc not defined in this function, raise the correct error... --- src/future/utils/surrogateescape.py | 2 +- tests/test_future/test_surrogateescape.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/future/utils/surrogateescape.py b/src/future/utils/surrogateescape.py index 398c3531..78ac11cb 100644 --- a/src/future/utils/surrogateescape.py +++ b/src/future/utils/surrogateescape.py @@ -83,7 +83,7 @@ def replace_surrogate_encode(mystring): # The following magic comes from Py3.3's Python/codecs.c file: if not 0xD800 <= code <= 0xDCFF: # Not a surrogate. Fail with the original exception. - raise exc + raise NotASurrogateError # mybytes = [0xe0 | (code >> 12), # 0x80 | ((code >> 6) & 0x3f), # 0x80 | (code & 0x3f)] diff --git a/tests/test_future/test_surrogateescape.py b/tests/test_future/test_surrogateescape.py index 0057ba36..7789ce9d 100644 --- a/tests/test_future/test_surrogateescape.py +++ b/tests/test_future/test_surrogateescape.py @@ -33,6 +33,12 @@ def test_encode_ascii_surrogateescape(self): b = payload.encode('ascii', 'surrogateescape') self.assertEqual(b, b'cMO2c3RhbA\xc3\xa1=\n') + def test_encode_ascii_unicode(self): + """ + Verify that exceptions are raised properly. + """ + self.assertRaises(UnicodeEncodeError, u'\N{SNOWMAN}'.encode, 'US-ASCII', 'surrogateescape') + @expectedFailurePY2 def test_encode_ascii_surrogateescape_non_newstr(self): """