From eec7a8490c317aee5ab5ce60a634c6cca1a88264 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 30 Jun 2013 06:12:57 +0100 Subject: [PATCH] Remove pickle from displaytags and move to json --- openlp/core/lib/formattingtags.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index ff091f2f4..146490395 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -30,6 +30,7 @@ Provide HTML Tag management and Formatting Tag access class """ import cPickle +import json from PyQt4 import QtCore @@ -71,8 +72,8 @@ class FormattingTags(object): if isinstance(tag[element], unicode): tag[element] = tag[element].encode('utf8') # Formatting Tags were also known as display tags. - Settings().setValue(u'displayTags/html_tags', - QtCore.QVariant(cPickle.dumps(tags) if tags else u'')) + Settings().setValue(u'formattingTags/html_tags', + QtCore.QVariant(json.dumps(tags) if tags else u'')) @staticmethod def load_tags(): @@ -167,12 +168,24 @@ class FormattingTags(object): FormattingTags.add_html_tags(temporary_tags) # Formatting Tags were also known as display tags. - user_expands = Settings().value(u'displayTags/html_tags', + user_expands = Settings().value(u'formattingTags/html_tags', QtCore.QVariant(u'')).toString() + json_loaded = True + if not user_expands: + user_expands = Settings().value(u'displayTags/html_tags', + QtCore.QVariant(u'')).toString() + json_loaded = False # cPickle only accepts str not unicode strings user_expands_string = str(user_expands) if user_expands_string: - user_tags = cPickle.loads(user_expands_string) + if json_loaded: + user_tags = json.loads(user_expands_string) + else: + user_tags = cPickle.loads(user_expands_string) + # move the formatting tags to json and remove old settings + Settings().setValue(u'formattingTags/html_tags', + QtCore.QVariant(json.dumps(user_tags))) + Settings().remove(u'displayTags/html_tags') for tag in user_tags: for element in tag: if isinstance(tag[element], str):