def start_folder(self, f, level):
dict = {}
+ comment = getattr(f, 'comment')
+ if comment: dict["annos"] = make_annos(comment)
dict["children"] = children = []
dict["dateAdded"] = f.add_date
dict["id"] = f.id
def bookmark(self, b, level):
dict = {}
+ comment = getattr(b, 'comment')
+ if comment: dict["annos"] = make_annos(comment)
charset = getattr(b, 'charset')
if charset: dict["charset"] = charset
dict["dateAdded"] = b.add_date
def ruler(self, r, level):
dict = {}
+ comment = getattr(r, 'comment')
+ if comment: dict["annos"] = make_annos(comment)
dict["dateAdded"] = r.add_date
dict["id"] = r.id
dict["index"] = r.index
folder.last_modified = _dict["lastModified"]
for record in _dict["children"]:
- if record["type"] == "text/x-moz-place":
+ if record["type"] == "text/x-moz-place-container":
+ folder = Folder(
+ add_date=record["dateAdded"],
+ comment=get_comment(record.get("annos")),
+ last_modified=record["lastModified"])
+ folder.id = record["id"]
+ folder.parent_idx = record["parent"]
+ folder.name = encode(record["title"])
+ self.current_folder.append(folder)
+ self.folder_stack.append(folder)
+ self.current_folder = folder
+ self.load_folder(folder, record)
+
+ elif record["type"] == "text/x-moz-place":
bookmark = Bookmark(
href=record["uri"],
add_date=record.get("dateAdded"),
last_modified=record.get("lastModified"),
+ comment=get_comment(record.get("annos")),
charset=record.get("charset"))
bookmark.id = record["id"]
bookmark.index = record.get("index")
bookmark.name = encode(record["title"])
self.current_folder.append(bookmark)
- elif record["type"] == "text/x-moz-place-container":
- folder = Folder(
- add_date=record["dateAdded"], comment=None,
- last_modified=record["lastModified"])
- folder.id = record["id"]
- folder.parent_idx = record["parent"]
- folder.name = encode(record["title"])
- self.current_folder.append(folder)
- self.folder_stack.append(folder)
- self.current_folder = folder
- self.load_folder(folder, record)
-
elif record["type"] == "text/x-moz-place-separator":
ruler = Ruler()
ruler.add_date = record["dateAdded"]
ruler.last_modified = record["lastModified"]
ruler.parent_idx = record["parent"]
ruler.name = encode(record["title"])
+ ruler.comment = get_comment(record.get("annos"))
self.current_folder.append(ruler)
else:
def encode(title):
return title.encode("UTF-8", "xmlcharrefreplace")
+
+def get_comment(annos):
+ if not annos:
+ return None
+
+ for a in annos:
+ if a["name"] == "bookmarkProperties/description" and \
+ a["type"] == 3:
+ return a["value"].encode('utf-8')
+
+ return None
+
+def make_annos(comment):
+ return [{
+ "expires": 4,
+ "flags": 0,
+ "mimeType": None,
+ "name": "bookmarkProperties/description",
+ "type": 3,
+ "value": comment.decode('utf-8')}]