Skip to content

Commit 4c6d0b9

Browse files
committed
Slightly less fail, perhaps
1 parent 220e2b9 commit 4c6d0b9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pyth/plugins/rtf15/reader.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,15 @@ def handle_control_symbol(self, symbol):
504504

505505

506506
def handle_u(self, 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')
507+
codepoint = int(codepoint)
508+
try:
509+
char = unichr(codepoint)
510+
except ValueError:
511+
# This ridiculous trick gives a surrogate pair for
512+
# non-BMP codepoints on narrow Pythons, which is
513+
# probably better than crashing
514+
char = struct.pack('<L', codepoint).decode('utf-32')
515+
511516
self.content.append(char)
512517
self.content.append(Skip(self.props.get('unicode_skip', 1)))
513518

0 commit comments

Comments
 (0)