From 95d15ae9ffbd2373b3ac810f3becc8c9c41b3e29 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 May 2017 08:32:55 +0530 Subject: [PATCH] Fix an infinite recursion error if the user chooses a non-existent default author search source Fixes #1690449 [Maximum recursion depth exceeded error](https://bugs.launchpad.net/calibre/+bug/1690449) --- src/calibre/ebooks/metadata/book/render.py | 7 ++++--- src/calibre/ebooks/metadata/search_internet.py | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/metadata/book/render.py b/src/calibre/ebooks/metadata/book/render.py index 6316e23421..2ff4ebcaa7 100644 --- a/src/calibre/ebooks/metadata/book/render.py +++ b/src/calibre/ebooks/metadata/book/render.py @@ -12,7 +12,7 @@ from binascii import hexlify from calibre import prepare_string_for_xml, force_unicode from calibre.ebooks.metadata import fmt_sidx, rating_to_stars -from calibre.ebooks.metadata.search_internet import name_for, url_for_author_search, url_for_book_search, qquote +from calibre.ebooks.metadata.search_internet import name_for, url_for_author_search, url_for_book_search, qquote, DEFAULT_AUTHOR_SOURCE from calibre.ebooks.metadata.sources.identify import urls_from_identifiers from calibre.constants import filesystem_encoding from calibre.library.comments import comments_to_html, markdown @@ -56,7 +56,7 @@ def search_href(search_term, value): return prepare_string_for_xml('search:' + hexlify(search.encode('utf-8')), True) -DEFAULT_AUTHOR_LINK = 'search-goodreads' +DEFAULT_AUTHOR_LINK = 'search-{}'.format(DEFAULT_AUTHOR_SOURCE) def author_search_href(which, title=None, author=None): @@ -67,7 +67,8 @@ def author_search_href(which, title=None, author=None): key, search_type = which.rpartition('-')[::2] name = name_for(key) if name is None: - return author_search_href(DEFAULT_AUTHOR_LINK, title=title, author=author) + search_type = 'author' + return author_search_href(DEFAULT_AUTHOR_LINK.partition('-')[2], title=title, author=author) if search_type == 'author': tt = _('Search {0} for the author: {1}').format(name, author) else: diff --git a/src/calibre/ebooks/metadata/search_internet.py b/src/calibre/ebooks/metadata/search_internet.py index d1b73fe4bc..5f0659390a 100644 --- a/src/calibre/ebooks/metadata/search_internet.py +++ b/src/calibre/ebooks/metadata/search_internet.py @@ -37,6 +37,9 @@ NAMES = { 'gimg': _('Google images'), } +DEFAULT_AUTHOR_SOURCE = 'goodreads' +assert DEFAULT_AUTHOR_SOURCE in AUTHOR_SEARCHES + name_for = NAMES.get all_book_searches = BOOK_SEARCHES.__iter__ all_author_searches = AUTHOR_SEARCHES.__iter__