Skip to content

Commit 220e2b9

Browse files
committed
Try a silly fix for non-BMP codepoints on narrow Pythons
1 parent 954e2c6 commit 220e2b9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pyth/plugins/rtf15/reader.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
This module is potentially compatible with RTF versions up to 1.9.1,
77
but may not ignore all necessary control groups.
88
"""
9-
import string, re, itertools
9+
import string, re, itertools, struct
1010

1111
from pyth import document
1212
from pyth.format import PythReader
@@ -504,7 +504,11 @@ def handle_control_symbol(self, symbol):
504504

505505

506506
def handle_u(self, codepoint):
507-
self.content.append(unichr(int(codepoint)))
507+
# This ridiculous trick gives a surrogate pair for
508+
# non-BMP codepoints on narrow Pythons, which is
509+
# probably better than crashing
510+
char = struct.pack('<L', 0x10000).decode('utf-32')
511+
self.content.append(char)
508512
self.content.append(Skip(self.props.get('unicode_skip', 1)))
509513

510514

0 commit comments

Comments
 (0)