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: ',

_______________________________________________
Mailing list: https://launchpad.net/~openlp-core
Post to     : openlp-core@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openlp-core
More help   : https://help.launchpad.net/ListHelp

Reply via email to