- if entity_re.match(part):
- part = unichr(int(part[2:-1])).encode(charset, "replace")
+ if part not in ("&", "<", ">", """) and \
+ entity_re.match(part):
+ _part = name2codepoint.get(part[1:-1], None)
+ if _part is not None:
+ part = unichr(_part).encode(charset)
+ output.append(part)
+ title = ''.join(output)
+
+ output = []
+ for part in num_entity_re.split(title):
+ if num_entity_re.match(part):
+ try:
+ part = unichr(int(part[2:-1])).encode(charset)
+ except UnicodeEncodeError:
+ pass # Leave the entity as is