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("'")
if ent == 'hellips':
ent = 'hellip'
if ent.lower().startswith(u'#x'):
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'#'):
if ent.startswith('#'):
try:
if ent[1] in ('x', 'X'):
num = int(ent[2:], 16)
else:
num = int(ent[1:])
except ValueError:
except:
return '&'+ent+';'
if encoding is None or num > 255:
return check(my_unichr(num))