forked from openlp/openlp
Fallback to manual encoding detection.
This commit is contained in:
parent
4c53cb5184
commit
1b75cc9c6b
@ -25,6 +25,7 @@ Presentationmanager song files into the current database.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import chardet
|
||||||
from lxml import objectify, etree
|
from lxml import objectify, etree
|
||||||
|
|
||||||
from openlp.core.ui.wizard import WizardStrings
|
from openlp.core.ui.wizard import WizardStrings
|
||||||
@ -42,7 +43,13 @@ class PresentationManagerImport(SongImport):
|
|||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
return
|
return
|
||||||
self.import_wizard.increment_progress_bar(WizardStrings.ImportingType % os.path.basename(file_path))
|
self.import_wizard.increment_progress_bar(WizardStrings.ImportingType % os.path.basename(file_path))
|
||||||
|
try:
|
||||||
tree = etree.parse(file_path, parser=etree.XMLParser(recover=True))
|
tree = etree.parse(file_path, parser=etree.XMLParser(recover=True))
|
||||||
|
except etree.XMLSyntaxError:
|
||||||
|
# Try to detect encoding and use it
|
||||||
|
file = open(file_path, mode='rb')
|
||||||
|
encoding = chardet.detect(file)['encoding']
|
||||||
|
tree = etree.parse(file_path, parser=etree.XMLParser(recover=True, encoding=encoding))
|
||||||
root = objectify.fromstring(etree.tostring(tree))
|
root = objectify.fromstring(etree.tostring(tree))
|
||||||
self.process_song(root)
|
self.process_song(root)
|
||||||
|
|
||||||
|
@ -42,9 +42,9 @@ class TestPresentationManagerFileImport(SongImportTestHelper):
|
|||||||
"""
|
"""
|
||||||
Test that loading a PresentationManager file works correctly
|
Test that loading a PresentationManager file works correctly
|
||||||
"""
|
"""
|
||||||
#self.file_import([os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.sng')],
|
self.file_import([os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.sng')],
|
||||||
# self.load_external_result_data(os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.json')))
|
self.load_external_result_data(os.path.join(TEST_PATH, 'Great Is Thy Faithfulness.json')))
|
||||||
#self.file_import([os.path.join(TEST_PATH, 'Agnus Dei.sng')],
|
self.file_import([os.path.join(TEST_PATH, 'Agnus Dei.sng')],
|
||||||
# self.load_external_result_data(os.path.join(TEST_PATH, 'Agnus Dei.json')))
|
self.load_external_result_data(os.path.join(TEST_PATH, 'Agnus Dei.json')))
|
||||||
self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.sng')],
|
self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.sng')],
|
||||||
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))
|
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))
|
||||||
|
Loading…
Reference in New Issue
Block a user