From: Oleg Broytman Date: Sun, 11 Dec 2011 03:27:44 +0000 (+0000) Subject: Encode values from unicode. X-Git-Tag: v4.5.3~31 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=d01d07aa733e85e7839e0ede051203eaa2868973;p=bookmarks_db.git Encode values from unicode. git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@345 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23 --- diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index 88429b6..5d34d16 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -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 ''