]> git.phdru.name Git - bookmarks_db.git/blobdiff - bkmk_parser.py
Store charset in the DB and the generated HTML.
[bookmarks_db.git] / bkmk_parser.py
index dfe7ce2f463ef783079dd996b739075dce6ae073..7ce99e8412447cbba334291783149f80cc2c3e46 100755 (executable)
@@ -1,7 +1,7 @@
 """
    Parser for Netscape Navigator's and Mozilla's bookmarks.html
 
-   Written by BroytMann. Copyright (C) 1997-2004 PhiloSoft Design
+   Written by BroytMann. Copyright (C) 1997-2005 PhiloSoft Design
 """
 
 
@@ -70,9 +70,18 @@ class BkmkParser(HTMLParser):
          else:
             global DEFAULT_CHARSET
             DEFAULT_CHARSET = sys.getdefaultencoding()
+            if DEFAULT_CHARSET == "ascii":
+               try:
+                  import locale
+               except ImportError:
+                  pass
+               else:
+                  DEFAULT_CHARSET = locale.getpreferredencoding()
 
 
    def start_title(self, attrs):
+      if DEFAULT_CHARSET:
+         self.accumulator += '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=%s">\n' % DEFAULT_CHARSET
       self.accumulator += "<TITLE>"
 
    def end_title(self):