]> git.phdru.name Git - bookmarks_db.git/blobdiff - bkmk_parser.py
Added docstrings, __{version,revision,etc}__ boilerplates.
[bookmarks_db.git] / bkmk_parser.py
old mode 100755 (executable)
new mode 100644 (file)
index 02cce68..2ec412c
@@ -1,9 +1,14 @@
-"""
-   Parser for Netscape Navigator's and Mozilla's bookmarks.html
+"""Parser for Netscape Navigator's and Mozilla's bookmarks.html
 
-   Written by BroytMann. Copyright (C) 1997-2007 PhiloSoft Design
+This file is a part of Bookmarks database and Internet robot.
 """
 
+__version__ = "$Revision$"[11:-2]
+__revision__ = "$Id$"[5:-2]
+__date__ = "$Date$"[7:-2]
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 1997-2011 PhiloSoft Design"
+__license__ = "GNU GPL"
 
 import sys, os
 from m_lib.net.www.html import HTMLParser
@@ -45,7 +50,7 @@ class BkmkParser(HTMLParser):
    def handle_data(self, data):
       if data:
          if DEFAULT_CHARSET:
-            data = unicode(data, self.charset, "replace").encode(DEFAULT_CHARSET, "replace")
+            data = unicode(data, self.charset, "replace").encode(DEFAULT_CHARSET, "xmlcharrefreplace")
          self.accumulator += data
 
 
@@ -135,9 +140,12 @@ class BkmkParser(HTMLParser):
 
    # Start a bookmark
    def start_a(self, attrs):
+      add_date = None
       last_visit = None
       last_modified = None
       keyword = None
+      icon = None
+      charset = None
 
       for attrname, value in attrs:
          value = value.strip()
@@ -151,9 +159,14 @@ class BkmkParser(HTMLParser):
             last_modified = value
          elif attrname == "shortcuturl":
             keyword = value
+         elif attrname == "icon":
+            icon = value
+         elif attrname == "last_charset":
+            charset = value
 
       debug("Bookmark points to: `%s'" % href)
-      bookmark = Bookmark(href, add_date, last_visit, last_modified, keyword or '')
+      bookmark = Bookmark(href, add_date, last_visit, last_modified,
+         keyword or '', '', icon, charset)
       self.current_object = bookmark
       self.current_folder.append(bookmark)
       self.urls += 1