mirror of https://github.com/python/cpython.git
Use the new htmlentitydefs.codepoint2name for test_xmlcharnamereplace()
This commit is contained in:
parent
1a4a9d0b0f
commit
1b0be2d4c6
|
@ -37,12 +37,6 @@ def test_xmlcharrefreplace(self):
|
|||
def test_xmlcharnamereplace(self):
|
||||
# This time use a named character entity for unencodable
|
||||
# characters, if one is available.
|
||||
names = {}
|
||||
for (key, value) in htmlentitydefs.entitydefs.items():
|
||||
if len(value)==1:
|
||||
names[unicode(value, "latin-1")] = unicode(key, "latin-1")
|
||||
else:
|
||||
names[unichr(int(value[2:-1]))] = unicode(key, "latin-1")
|
||||
|
||||
def xmlcharnamereplace(exc):
|
||||
if not isinstance(exc, UnicodeEncodeError):
|
||||
|
@ -50,7 +44,7 @@ def xmlcharnamereplace(exc):
|
|||
l = []
|
||||
for c in exc.object[exc.start:exc.end]:
|
||||
try:
|
||||
l.append(u"&%s;" % names[c])
|
||||
l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)])
|
||||
except KeyError:
|
||||
l.append(u"&#%d;" % ord(c))
|
||||
return (u"".join(l), exc.end)
|
||||
|
|
Loading…
Reference in New Issue