8000 htmlentityreplace_errors now handles UnicodeTranslateError the same a… · awesome-python/html5lib-python@eb70d51 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb70d51

Browse files
committed
htmlentityreplace_errors now handles UnicodeTranslateError the same as UnicodeEncodeError; inspired from xmlcharrefreplace behavior described in PEP293 <http://www.python.org/dev/peps/pep-0293/>
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40649
1 parent b3eeca8 commit eb70d51

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/serializer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@
2626
# prefer &lt; over &LT; and similarly for &amp;, &gt;, etc.
2727
encode_entity_map[v] = k
2828

29-
def htmlentityreplace_errors(ex):
30-
if isinstance(ex, UnicodeEncodeError):
29+
def htmlentityreplace_errors(exc):
30+
if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)):
3131
res = []
32-
for c in ex.object[ex.start:ex.end]:
32+
for c in ex.object[exc.start:exc.end]:
3333
c = encode_entity_map.get(c)
3434
if c:
3535
res.append("&")
3636
res.append(c)
3737
res.append(";")
3838
else:
39-
res.append(c.encode(ex.encoding, "xmlcharrefreplace"))
40-
return (u"".join(res), ex.end)
39+
res.append(c.encode(exc.encoding, "xmlcharrefreplace"))
40+
return (u"".join(res), exc.end)
4141
else:
42-
return xmlcharrefreplace_errors(ex)
42+
return xmlcharrefreplace_errors(exc)
4343

4444
register_error(unicode_encode_errors, htmlentityreplace_errors)
4545

0 commit comments

Comments
 (0)
0