From 72ba94d39089074a90aa7d4b38f22dd2b592440f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 3 Apr 2013 16:53:30 +0200 Subject: [PATCH] replaced cPickle by pickle --- openlp/core/lib/formattingtags.py | 8 +++----- openlp/core/ui/servicemanager.py | 8 ++++---- tests/functional/openlp_core_lib/test_formattingtags.py | 8 ++++---- tests/functional/openlp_core_lib/test_serviceitem.py | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index b2d8f6ea7..028abff35 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -29,7 +29,7 @@ """ Provide HTML Tag management and Formatting Tag access class """ -import cPickle +import pickle from openlp.core.lib import Settings, translate @@ -66,7 +66,7 @@ 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', cPickle.dumps(tags) if tags else u'') + Settings().setValue(u'displayTags/html_tags', pickle.dumps(tags) if tags else u'') @staticmethod def load_tags(): @@ -159,10 +159,8 @@ class FormattingTags(object): # Formatting Tags were also known as display tags. user_expands = Settings().value(u'displayTags/html_tags') - # cPickle only accepts str not unicode strings - user_expands_string = str(user_expands) if user_expands_string: - user_tags = cPickle.loads(user_expands_string) + user_tags = pickle.loads(user_expands_string) for tag in user_tags: for element in tag: if isinstance(tag[element], str): diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 6490d2b8d..1cfb21d2c 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -30,7 +30,7 @@ The service manager sets up, loads, saves and manages services. """ import cgi -import cPickle +import pickle import logging import os import shutil @@ -507,7 +507,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog): file_size = os.path.getsize(file_item) total_size += file_size log.debug(u'ServiceManager.save_file - ZIP contents size is %i bytes' % total_size) - service_content = cPickle.dumps(service) + service_content = pickle.dumps(service) # Usual Zip file cannot exceed 2GiB, file with Zip64 cannot be extracted using unzip in UNIX. allow_zip_64 = (total_size > 2147483648 + len(service_content)) log.debug(u'ServiceManager.save_file - allowZip64 is %s' % allow_zip_64) @@ -580,7 +580,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog): #TODO: check for file item on save. service.append({u'serviceitem': service_item}) self.main_window.increment_progress_bar() - service_content = cPickle.dumps(service) + service_content = pickle.dumps(service) zip_file = None success = True self.main_window.increment_progress_bar() @@ -697,7 +697,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog): p_file = os.path.join(self.servicePath, osfile) if 'p_file' in locals(): file_to = open(p_file, u'r') - items = cPickle.load(file_to) + items = pickle.load(file_to) file_to.close() self.new_file() self.set_file_name(file_name) diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py index 26d87f466..721032033 100644 --- a/tests/functional/openlp_core_lib/test_formattingtags.py +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -33,11 +33,11 @@ class TestFormattingTags(TestCase): """ with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ - patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + patch(u'openlp.core.lib.formattingtags.pickle') as mocked_pickle: # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate mocked_settings.value.return_value = u'' - mocked_cPickle.load.return_value = [] + mocked_pickle.load.return_value = [] # WHEN: Get the display tags. FormattingTags.load_tags() @@ -54,11 +54,11 @@ class TestFormattingTags(TestCase): """ with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ - patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + patch(u'openlp.core.lib.formattingtags.pickle') as mocked_pickle: # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate mocked_settings.value.return_value = u'' - mocked_cPickle.loads.side_effect = [[], [TAG]] + mocked_pickle.loads.side_effect = [[], [TAG]] # WHEN: Get the display tags. FormattingTags.load_tags() diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index d50ddc978..0f1730820 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -2,7 +2,7 @@ Package to test the openlp.core.lib package. """ import os -import cPickle +import pickle from unittest import TestCase from mock import MagicMock, patch @@ -272,7 +272,7 @@ class TestServiceItem(TestCase): service_file = os.path.join(TEST_PATH, name) try: open_file = open(service_file, u'r') - items = cPickle.load(open_file) + items = pickle.load(open_file) first_line = items[0] except IOError: first_line = u''