Fix #6305 (entity_to_unicode hexmess)

This commit is contained in:
Kovid Goyal 2010-07-27 13:28:16 -06:00
parent f3cfd09a54
commit c9d31cb121

View File

@ -413,15 +413,13 @@ def entity_to_unicode(match, exceptions=[], encoding='cp1252',
return check("'") return check("'")
if ent == 'hellips': if ent == 'hellips':
ent = 'hellip' ent = 'hellip'
if ent.lower().startswith(u'#x'): if ent.startswith('#'):
num = int(ent[2:], 16)
if encoding is None or num > 255:
return check(my_unichr(num))
return check(chr(num).decode(encoding))
if ent.startswith(u'#'):
try: try:
num = int(ent[1:]) if ent[1] in ('x', 'X'):
except ValueError: num = int(ent[2:], 16)
else:
num = int(ent[1:])
except:
return '&'+ent+';' return '&'+ent+';'
if encoding is None or num > 255: if encoding is None or num > 255:
return check(my_unichr(num)) return check(my_unichr(num))