From d0c500703d5866240273e7f629b7fbcd2b0f2f28 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Sep 2011 20:31:38 -0400 Subject: [PATCH] Store: ebook download, fix all unicode decode errors. --- src/calibre/__init__.py | 6 +----- src/calibre/gui2/ebook_download.py | 8 ++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index ef6a383925..358a7ee4bf 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -17,7 +17,6 @@ from calibre.constants import (iswindows, isosx, islinux, isfrozen, win32event, win32api, winerror, fcntl, filesystem_encoding, plugins, config_dir) from calibre.startup import winutil, winutilerror -from calibre.utils.filenames import ascii_filename if False and islinux and not getattr(sys, 'frozen', False): # Imported before PyQt4 to workaround PyQt4 util-linux conflict discovered on gentoo @@ -649,10 +648,7 @@ def get_download_filename(url, cookie_file=None): if not filename: filename = last_part_name - filename, ext = os.path.splitext(filename) - filename = filename[:60] + ext - - return ascii_filename(filename) + return filename def human_readable(size): """ Convert a size in bytes into a human readable form """ diff --git a/src/calibre/gui2/ebook_download.py b/src/calibre/gui2/ebook_download.py index d39ea47e52..1b2f8b38d0 100644 --- a/src/calibre/gui2/ebook_download.py +++ b/src/calibre/gui2/ebook_download.py @@ -16,6 +16,7 @@ from calibre.ebooks import BOOK_EXTENSIONS from calibre.gui2 import Dispatcher from calibre.gui2.threaded_jobs import ThreadedJob from calibre.ptempfile import PersistentTemporaryFile +from calibre.utils.filenames import ascii_filename class EbookDownload(object): @@ -45,6 +46,9 @@ class EbookDownload(object): if not filename: filename = get_download_filename(url, cookie_file) + filename, ext = os.path.splitext(filename) + filename = filename[:60] + ext + filename = ascii_filename(filename) br = browser() if cookie_file: @@ -84,7 +88,7 @@ class EbookDownload(object): gui_ebook_download = EbookDownload() def start_ebook_download(callback, job_manager, gui, cookie_file=None, url='', filename='', save_loc='', add_to_lib=True, tags=[]): - description = _('Downloading %s') % filename if filename else url + description = _('Downloading %s') % filename.decode('utf-8', 'ignore') if filename else url.decode('utf-8', 'ignore') job = ThreadedJob('ebook_download', description, gui_ebook_download, (gui, cookie_file, url, filename, save_loc, add_to_lib, tags), {}, callback, max_concurrent_count=2, killable=False) job_manager.run_threaded_job(job) @@ -96,7 +100,7 @@ class EbookDownloadMixin(object): if isinstance(tags, basestring): tags = tags.split(',') start_ebook_download(Dispatcher(self.downloaded_ebook), self.job_manager, self, cookie_file, url, filename, save_loc, add_to_lib, tags) - self.status_bar.show_message(_('Downloading') + ' ' + filename if filename else url, 3000) + self.status_bar.show_message(_('Downloading') + ' ' + filename.decode('utf-8', 'ignore') if filename else url.decode('utf-8', 'ignore'), 3000) def downloaded_ebook(self, job): if job.failed: