replaced cPickle by pickle

This commit is contained in:
Andreas Preikschat 2013-04-03 16:53:30 +02:00
parent 4b76db7ad7
commit 72ba94d390
4 changed files with 13 additions and 15 deletions

View File

@ -29,7 +29,7 @@
""" """
Provide HTML Tag management and Formatting Tag access class Provide HTML Tag management and Formatting Tag access class
""" """
import cPickle import pickle
from openlp.core.lib import Settings, translate from openlp.core.lib import Settings, translate
@ -66,7 +66,7 @@ class FormattingTags(object):
if isinstance(tag[element], unicode): if isinstance(tag[element], unicode):
tag[element] = tag[element].encode('utf8') tag[element] = tag[element].encode('utf8')
# Formatting Tags were also known as display tags. # 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 @staticmethod
def load_tags(): def load_tags():
@ -159,10 +159,8 @@ class FormattingTags(object):
# Formatting Tags were also known as display tags. # Formatting Tags were also known as display tags.
user_expands = Settings().value(u'displayTags/html_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: if user_expands_string:
user_tags = cPickle.loads(user_expands_string) user_tags = pickle.loads(user_expands_string)
for tag in user_tags: for tag in user_tags:
for element in tag: for element in tag:
if isinstance(tag[element], str): if isinstance(tag[element], str):

View File

@ -30,7 +30,7 @@
The service manager sets up, loads, saves and manages services. The service manager sets up, loads, saves and manages services.
""" """
import cgi import cgi
import cPickle import pickle
import logging import logging
import os import os
import shutil import shutil
@ -507,7 +507,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
file_size = os.path.getsize(file_item) file_size = os.path.getsize(file_item)
total_size += file_size total_size += file_size
log.debug(u'ServiceManager.save_file - ZIP contents size is %i bytes' % total_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. # 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)) allow_zip_64 = (total_size > 2147483648 + len(service_content))
log.debug(u'ServiceManager.save_file - allowZip64 is %s' % allow_zip_64) 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. #TODO: check for file item on save.
service.append({u'serviceitem': service_item}) service.append({u'serviceitem': service_item})
self.main_window.increment_progress_bar() self.main_window.increment_progress_bar()
service_content = cPickle.dumps(service) service_content = pickle.dumps(service)
zip_file = None zip_file = None
success = True success = True
self.main_window.increment_progress_bar() self.main_window.increment_progress_bar()
@ -697,7 +697,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
p_file = os.path.join(self.servicePath, osfile) p_file = os.path.join(self.servicePath, osfile)
if 'p_file' in locals(): if 'p_file' in locals():
file_to = open(p_file, u'r') file_to = open(p_file, u'r')
items = cPickle.load(file_to) items = pickle.load(file_to)
file_to.close() file_to.close()
self.new_file() self.new_file()
self.set_file_name(file_name) self.set_file_name(file_name)

View File

@ -33,11 +33,11 @@ class TestFormattingTags(TestCase):
""" """
with patch(u'openlp.core.lib.translate') as mocked_translate, \ with patch(u'openlp.core.lib.translate') as mocked_translate, \
patch(u'openlp.core.lib.settings') as mocked_settings, \ 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. # GIVEN: Our mocked modules and functions.
mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate
mocked_settings.value.return_value = u'' mocked_settings.value.return_value = u''
mocked_cPickle.load.return_value = [] mocked_pickle.load.return_value = []
# WHEN: Get the display tags. # WHEN: Get the display tags.
FormattingTags.load_tags() FormattingTags.load_tags()
@ -54,11 +54,11 @@ class TestFormattingTags(TestCase):
""" """
with patch(u'openlp.core.lib.translate') as mocked_translate, \ with patch(u'openlp.core.lib.translate') as mocked_translate, \
patch(u'openlp.core.lib.settings') as mocked_settings, \ 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. # GIVEN: Our mocked modules and functions.
mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate
mocked_settings.value.return_value = u'' mocked_settings.value.return_value = u''
mocked_cPickle.loads.side_effect = [[], [TAG]] mocked_pickle.loads.side_effect = [[], [TAG]]
# WHEN: Get the display tags. # WHEN: Get the display tags.
FormattingTags.load_tags() FormattingTags.load_tags()

View File

@ -2,7 +2,7 @@
Package to test the openlp.core.lib package. Package to test the openlp.core.lib package.
""" """
import os import os
import cPickle import pickle
from unittest import TestCase from unittest import TestCase
from mock import MagicMock, patch from mock import MagicMock, patch
@ -272,7 +272,7 @@ class TestServiceItem(TestCase):
service_file = os.path.join(TEST_PATH, name) service_file = os.path.join(TEST_PATH, name)
try: try:
open_file = open(service_file, u'r') open_file = open(service_file, u'r')
items = cPickle.load(open_file) items = pickle.load(open_file)
first_line = items[0] first_line = items[0]
except IOError: except IOError:
first_line = u'' first_line = u''