From: Oleg Broytman Date: Sun, 25 Jul 2010 20:19:23 +0000 (+0000) Subject: Load/store comments. X-Git-Tag: v4.5.3~142 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=1bf29b390bf31ab36e581102a6316c79d272d4e1;p=bookmarks_db.git Load/store comments. git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@234 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23 --- diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index fd77d59..77b3a03 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -29,6 +29,8 @@ class storage_json(Walker): 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 @@ -47,6 +49,8 @@ class storage_json(Walker): 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 @@ -62,6 +66,8 @@ class storage_json(Walker): 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 @@ -114,11 +120,25 @@ class storage_json(Walker): 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") @@ -126,18 +146,6 @@ class storage_json(Walker): 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"] @@ -146,6 +154,7 @@ class storage_json(Walker): 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: @@ -159,3 +168,23 @@ class storage_json(Walker): 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')}]