forked from openlp/openlp
Supposedly fix BOM mess for utf-8 files. We assume no other file would begin with BOM, whatever encoding they have.
This commit is contained in:
parent
4949f88f28
commit
ca6250ae3b
|
@ -80,6 +80,9 @@ def get_text_file_string(text_file):
|
||||||
content_string = None
|
content_string = None
|
||||||
try:
|
try:
|
||||||
file_handle = open(text_file, u'r')
|
file_handle = open(text_file, u'r')
|
||||||
|
if not file_handle.read(3) == '\xEF\xBB\xBF':
|
||||||
|
# no BOM was found
|
||||||
|
file_handle.seek(0)
|
||||||
content = file_handle.read()
|
content = file_handle.read()
|
||||||
content_string = content.decode(u'utf-8')
|
content_string = content.decode(u'utf-8')
|
||||||
except (IOError, UnicodeError):
|
except (IOError, UnicodeError):
|
||||||
|
|
|
@ -28,17 +28,7 @@
|
||||||
The :mod:`cvsbible` modules provides a facility to import bibles from a set of
|
The :mod:`cvsbible` modules provides a facility to import bibles from a set of
|
||||||
CSV files.
|
CSV files.
|
||||||
|
|
||||||
The module expects two mandatory files containing the books and the verses and
|
The module expects two mandatory files containing the books and the verses.
|
||||||
will accept an optional third file containing the testaments.
|
|
||||||
|
|
||||||
The format of the testament file is:
|
|
||||||
|
|
||||||
<testament_id>,<testament_name>
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
1,Old Testament
|
|
||||||
2,New Testament
|
|
||||||
|
|
||||||
The format of the books file is:
|
The format of the books file is:
|
||||||
|
|
||||||
|
@ -110,6 +100,9 @@ class CSVBible(BibleDB):
|
||||||
try:
|
try:
|
||||||
details = get_file_encoding(self.booksfile)
|
details = get_file_encoding(self.booksfile)
|
||||||
books_file = open(self.booksfile, 'r')
|
books_file = open(self.booksfile, 'r')
|
||||||
|
if not books_file.read(3) == '\xEF\xBB\xBF':
|
||||||
|
# no BOM was found
|
||||||
|
books_file.seek(0)
|
||||||
books_reader = csv.reader(books_file, delimiter=',', quotechar='"')
|
books_reader = csv.reader(books_file, delimiter=',', quotechar='"')
|
||||||
for line in books_reader:
|
for line in books_reader:
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
|
@ -144,6 +137,9 @@ class CSVBible(BibleDB):
|
||||||
book_ptr = None
|
book_ptr = None
|
||||||
details = get_file_encoding(self.versesfile)
|
details = get_file_encoding(self.versesfile)
|
||||||
verse_file = open(self.versesfile, 'rb')
|
verse_file = open(self.versesfile, 'rb')
|
||||||
|
if not verse_file.read(3) == '\xEF\xBB\xBF':
|
||||||
|
# no BOM was found
|
||||||
|
verse_file.seek(0)
|
||||||
verse_reader = csv.reader(verse_file, delimiter=',', quotechar='"')
|
verse_reader = csv.reader(verse_file, delimiter=',', quotechar='"')
|
||||||
for line in verse_reader:
|
for line in verse_reader:
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
|
|
|
@ -78,8 +78,7 @@ class OSISBible(BibleDB):
|
||||||
fbibles = open(filepath, u'r')
|
fbibles = open(filepath, u'r')
|
||||||
for line in fbibles:
|
for line in fbibles:
|
||||||
book = line.split(u',')
|
book = line.split(u',')
|
||||||
self.books[book[0]] = (book[1].lstrip().rstrip(),
|
self.books[book[0]] = (book[1].strip(), book[2].strip())
|
||||||
book[2].lstrip().rstrip())
|
|
||||||
except IOError:
|
except IOError:
|
||||||
log.exception(u'OSIS bible import failed')
|
log.exception(u'OSIS bible import failed')
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -75,6 +75,9 @@ class CCLIFileImport(SongImport):
|
||||||
details = chardet.detect(detect_content)
|
details = chardet.detect(detect_content)
|
||||||
detect_file.close()
|
detect_file.close()
|
||||||
infile = codecs.open(filename, u'r', details['encoding'])
|
infile = codecs.open(filename, u'r', details['encoding'])
|
||||||
|
if not infile.read(3) == '\xEF\xBB\xBF':
|
||||||
|
# not UTF or no BOM was found
|
||||||
|
infile.seek(0)
|
||||||
lines = infile.readlines()
|
lines = infile.readlines()
|
||||||
infile.close()
|
infile.close()
|
||||||
ext = os.path.splitext(filename)[1]
|
ext = os.path.splitext(filename)[1]
|
||||||
|
|
Loading…
Reference in New Issue