+ def do_link(self, attrs):
+ has_icon = False
+ href = None
+
+ for attrname, value in attrs:
+ if value:
+ value = value.strip().lower()
+ if (attrname == 'rel') and (value in ('icon', 'shortcut icon')):
+ has_icon = True
+ elif attrname == 'href':
+ href = value
+
+ if has_icon:
+ self.icon = href
+ else:
+ self.icon = None
+
+
+import re
+entity_re = re.compile("(&#[0-9]+;)")
+
+def recode_entities(title, charset):
+ output = []
+ for part in entity_re.split(title):
+ if entity_re.match(part):
+ part = unichr(int(part[2:-1])).encode(charset, "replace")
+ output.append(part)
+
+ return ''.join(output)
+
+