]> git.phdru.name Git - bookmarks_db.git/commitdiff
Encode values from unicode.
authorOleg Broytman <phd@phdru.name>
Sun, 11 Dec 2011 03:27:44 +0000 (03:27 +0000)
committerOleg Broytman <phd@phdru.name>
Sun, 11 Dec 2011 03:27:44 +0000 (03:27 +0000)
git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@345 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23

Storage/bkmk_stjson.py

index 88429b639b793033abd64dd03fc7659327041ec0..5d34d165f6cb27fae1a4fe4f7ee9a874719dc79d 100644 (file)
@@ -139,7 +139,7 @@ class storage_json(Walker):
         folder.index = fdict.get("index")
         folder.parent_idx = fdict.get("parent")
         folder.root = fdict.get("root")
-        folder.name = encode(fdict["title"])
+        folder.name = encode_title(fdict["title"])
 
         for record in fdict["children"]:
             if record["type"] == "text/x-moz-place-container":
@@ -154,16 +154,16 @@ class storage_json(Walker):
 
             elif record["type"] == "text/x-moz-place":
                 bookmark = Bookmark(
-                    href=record["uri"],
+                    href=record["uri"].encode('utf-8'),
                     add_date=record.get("dateAdded"),
                     last_modified=record.get("lastModified"),
-                    keyword=record.get("keyword"),
+                    keyword=get_str(record, "keyword"),
                     comment=get_comment(record.get("annos")),
-                    charset=record.get("charset"))
+                    charset=get_str(record, "charset"))
                 bookmark.id = record["id"]
                 bookmark.index = record.get("index")
                 bookmark.parent_idx = record["parent"]
-                bookmark.name = encode(record["title"])
+                bookmark.name = encode_title(record["title"])
                 self.current_folder.append(bookmark)
 
             elif record["type"] == "text/x-moz-place-separator":
@@ -173,7 +173,7 @@ class storage_json(Walker):
                 ruler.index = record["index"]
                 ruler.last_modified = record["lastModified"]
                 ruler.parent_idx = record["parent"]
-                ruler.name = encode(record["title"])
+                ruler.name = encode_title(record["title"])
                 ruler.comment = get_comment(record.get("annos"))
                 self.current_folder.append(ruler)
 
@@ -186,9 +186,14 @@ class storage_json(Walker):
         else:
             self.current_folder = None
 
-def encode(title):
+def encode_title(title):
     return title.encode("UTF-8", "xmlcharrefreplace")
 
+def get_str(record, name):
+    if name in record:
+        return record[name].encode('utf-8')
+    return ''
+
 def get_comment(annos):
     if not annos:
         return ''