Fixes to encoding handling in txt2lrf.

This commit is contained in:
Kovid Goyal 2007-06-01 15:21:45 +00:00
parent 5852f04428
commit 2a1edb45c6
2 changed files with 9 additions and 4 deletions

View File

@ -13,7 +13,7 @@
## with this program; if not, write to the Free Software Foundation, Inc., ## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
''' E-book management software''' ''' E-book management software'''
__version__ = "0.3.43" __version__ = "0.3.44"
__docformat__ = "epytext" __docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>" __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"

View File

@ -87,14 +87,19 @@ def convert_txt(path, options):
book.append(pg) book.append(pg)
lines = "" lines = ""
try: try:
lines = codecs.open(path, 'rb', 'ascii').readlines() lines = codecs.open(path, 'rb', options.encoding).readlines()
print 'huh'
except UnicodeDecodeError: except UnicodeDecodeError:
try: try:
lines = codecs.open(path, 'rb', 'cp1252').readlines() lines = codecs.open(path, 'rb', 'cp1252').readlines()
except UnicodeDecodeError: except UnicodeDecodeError:
try: try:
lines = codecs.open(path, 'rb', 'iso-8859-1').readlines() lines = codecs.open(path, 'rb', 'iso-8859-1').readlines()
except UnicodeDecodeError:
try:
lines = codecs.open(path, 'rb', 'koi8_r').readlines()
except UnicodeDecodeError:
try:
lines = codecs.open(path, 'rb', 'koi8_u').readlines()
except UnicodeDecodeError: except UnicodeDecodeError:
lines = codecs.open(path, 'rb', 'utf8').readlines() lines = codecs.open(path, 'rb', 'utf8').readlines()
for line in lines: for line in lines: