]> git.phdru.name Git - bookmarks_db.git/commitdiff
Recode entities before num. entities.
authorOleg Broytman <phd@phdru.name>
Mon, 11 Feb 2008 19:58:39 +0000 (19:58 +0000)
committerOleg Broytman <phd@phdru.name>
Mon, 11 Feb 2008 19:58:39 +0000 (19:58 +0000)
git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@171 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23

Robots/parse_html.py

index dbca770543d7b6cc7b4e4c367413e53d505b1b5d..888e27c9f79a2f7d6310dd3129454d8b6b360d67 100755 (executable)
@@ -33,23 +33,18 @@ num_entity_re = re.compile("(&#[0-9]+;)")
 
 def recode_entities(title, charset):
    output = []
-   for part in num_entity_re.split(title):
+   for part in entity_re.split(title):
+      if entity_re.match(part):
+         part = entitydefs.get(part[1:-1], part)
+      output.append(part)
+
+   output2 = []
+   for part in num_entity_re.split(''.join(output)):
       if num_entity_re.match(part):
          try:
             part = unichr(int(part[2:-1])).encode(charset)
          except UnicodeEncodeError:
             pass # Leave the entity as is
-      output.append(part)
-
-   output2 = []
-   for part in entity_re.split(''.join(output)):
-      if entity_re.match(part):
-         part = entitydefs.get(part[1:-1], part)
-         if num_entity_re.match(part):
-            try:
-               part = unichr(int(part[2:-1])).encode(charset)
-            except UnicodeEncodeError:
-               pass # Leave the entity as is
       output2.append(part)
 
    return ''.join(output2)