]> git.phdru.name Git - bookmarks_db.git/commitdiff
Get default charset from m_lib, if available.
authorOleg Broytman <phd@phdru.name>
Thu, 14 Apr 2011 15:20:20 +0000 (15:20 +0000)
committerOleg Broytman <phd@phdru.name>
Thu, 14 Apr 2011 15:20:20 +0000 (15:20 +0000)
git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@331 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23

bkmk_parser.py

index e3b3db02532567aef8060c4546f1f3a6af6039e2..02b20d780c56003aea95d30827e4a8d85e6c4ef4 100644 (file)
@@ -37,7 +37,10 @@ else:
    dump_names = debug
 
 
-DEFAULT_CHARSET = None
+try:
+    from m_lib.defenc import default_encoding as DEFAULT_CHARSET
+except ImportError:
+    DEFAULT_CHARSET = None
 
 class BkmkParser(HTMLParser):
    def __init__(self):
@@ -46,12 +49,12 @@ class BkmkParser(HTMLParser):
       self.urls = 0
       self.objects = 0
 
-      self.charset = ""
+      self.charset = None
       self.recode = None
 
    def handle_data(self, data):
       if data:
-         if DEFAULT_CHARSET:
+         if self.charset and DEFAULT_CHARSET:
             data = unicode(data, self.charset, "replace").encode(DEFAULT_CHARSET, "xmlcharrefreplace")
          self.accumulator += data
 
@@ -73,16 +76,6 @@ class BkmkParser(HTMLParser):
             self.charset = content.split('=')[1]
          except IndexError:
             pass
-         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: