Skip to content

Commit

Permalink
Try a silly fix for non-BMP codepoints on narrow Pythons
Browse files Browse the repository at this point in the history
  • Loading branch information
brendonh committed Aug 18, 2010
1 parent 954e2c6 commit 220e2b9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pyth/plugins/rtf15/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
This module is potentially compatible with RTF versions up to 1.9.1,
but may not ignore all necessary control groups.
"""
import string, re, itertools
import string, re, itertools, struct

from pyth import document
from pyth.format import PythReader
Expand Down Expand Up @@ -504,7 +504,11 @@ def handle_control_symbol(self, symbol):


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


Expand Down

0 comments on commit 220e2b9

Please sign in to comment.