Skip to content

Commit 6b42a4c

Browse files
committed
Make importing html5lib not throw an exception on UCS2 Python.
1 parent c12357b commit 6b42a4c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

html5lib/serializer/htmlserializer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
for k, v in entities.items():
2828
if v != "&" and encode_entity_map.get(v) != k.lower():
2929
# prefer < over < and similarly for &, >, etc.
30-
encode_entity_map[ord(v)] = k
30+
if len(v) == 2:
31+
v = utils.surrogatePairToCodepoint(v)
32+
else:
33+
v = ord(v)
34+
encode_entity_map[v] = k
3135

3236
def htmlentityreplace_errors(exc):
3337
if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)):

0 commit comments

Comments
 (0)