]> git.phdru.name Git - bookmarks_db.git/commitdiff
Do not encode non-encodeable entities.
authorOleg Broytman <phd@phdru.name>
Sat, 22 Dec 2007 20:52:14 +0000 (20:52 +0000)
committerOleg Broytman <phd@phdru.name>
Sat, 22 Dec 2007 20:52:14 +0000 (20:52 +0000)
git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@124 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23

Robots/parse_html.py

index c5c9eb6831e0db333cf95cd25314dbc453a5e28a..666c7071fd0072a8249b9e2bf8a0ba4cb4a6e3c6 100755 (executable)
@@ -30,7 +30,10 @@ 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")
+         try:
+            part = unichr(int(part[2:-1])).encode(charset)
+         except UnicodeEncodeError:
+            pass # Leave the entity as is
       output.append(part)
 
    return ''.join(output)