]> git.phdru.name Git - bookmarks_db.git/blobdiff - Storage/bkmk_stjson.py
Cleanup code: use 4 spaces
[bookmarks_db.git] / Storage / bkmk_stjson.py
index 43f5881183ba14cb12e54ed18b96b9bd267f3a7c..5fbeda88ea110d2098c30594b00b86aba9df24b6 100644 (file)
@@ -5,16 +5,16 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2010-2014 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2010-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 __all__ = ['storage_json']
 
 
 try:
-   import json
+    import json
 except ImportError:
-   import simplejson as json
+    import simplejson as json
 
 from bkmk_objects import Folder, Bookmark, Ruler, Walker
 
@@ -84,7 +84,7 @@ class storage_json(Walker):
         if guid: dict["guid"] = guid
         dict["index"] = r.index
         dict["lastModified"] = convert_date_to_json(r.last_modified)
-        dict["title"] = r.name.decode('utf-8')
+        if r.name: dict["title"] = r.name.decode('utf-8')
         dict["type"] = "text/x-moz-place-separator"
         self.folder_stack[-1].append(dict)
 
@@ -115,9 +115,9 @@ class storage_json(Walker):
         self.current_folder = root_folder
 
         if "type" not in bookmarks_dict:
-           bookmarks_dict["id"] = "0"
-           bookmarks_dict["title"] = ""
-           bookmarks_dict["type"] = "text/x-moz-place-container"
+            bookmarks_dict["id"] = "0"
+            bookmarks_dict["title"] = ""
+            bookmarks_dict["type"] = "text/x-moz-place-container"
         self.load_folder(root_folder, bookmarks_dict)
         if self.folder_stack:
             raise RuntimeError('Excessive folder stack: %s' % self.folder_stack)
@@ -168,7 +168,7 @@ class storage_json(Walker):
                 ruler.id = record["id"]
                 ruler.index = record["index"]
                 ruler.last_modified = convert_date_from_json(record.get("lastModified"))
-                ruler.name = encode_title(record["title"])
+                ruler.name = encode_title(record.get("title"))
                 ruler.comment = get_comment(record.get("annos"))
                 self.current_folder.append(ruler)
 
@@ -195,7 +195,9 @@ def convert_date_from_json(date):
     return date
 
 def encode_title(title):
-    return title.encode("UTF-8", "xmlcharrefreplace")
+    if title:
+        return title.encode("UTF-8", "xmlcharrefreplace")
+    return title
 
 def get_str(record, name):
     if name in record: