← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~mahfiaz/openlp/fixes_and_improvements into lp:openlp

 

mahfiaz has proposed merging lp:~mahfiaz/openlp/fixes_and_improvements into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~mahfiaz/openlp/fixes_and_improvements/+merge/50614

This *should* fix http://support.openlp.org/issues/99 , problem, when first encoding-dependent character appears after first 2kb in file.
Unfortunately I cannot test it, since I have got no CCLI files, no good nor bogus ones.
-- 
https://code.launchpad.net/~mahfiaz/openlp/fixes_and_improvements/+merge/50614
Your team OpenLP Core is requested to review the proposed merge of lp:~mahfiaz/openlp/fixes_and_improvements into lp:openlp.
=== modified file 'openlp/plugins/songs/lib/cclifileimport.py'
--- openlp/plugins/songs/lib/cclifileimport.py	2011-02-19 20:31:21 +0000
+++ openlp/plugins/songs/lib/cclifileimport.py	2011-02-21 15:23:33 +0000
@@ -78,7 +78,20 @@
                     details = chardet.detect(detect_content)
                 detect_file.close()
                 infile = codecs.open(filename, u'r', details['encoding'])
-                lines = infile.readlines()
+                try:
+                    lines = infile.readlines()
+                    infile.close()
+                except UnicodeDecodeError:
+                    # First 2kB were not sufficient to detect file encoding.
+                    # This time we read entire file.
+                    detect_file = open(filename, u'r')
+                    detect_content = detect_file.read()
+                    details = chardet.detect(detect_content)
+                    detect_file.close()
+                    # We read the contents again. Should it be a try as well?
+                    infile = codecs.open(filename, u'r', details['encoding'])
+                    lines = infile.readlines()
+                    infile.close()
                 ext = os.path.splitext(filename)[1]
                 if ext.lower() == u'.usr':
                     log.info(u'SongSelect .usr format file found %s: ',