mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix clicking on author name in book details panel to search in goodreads not working if author has more than two parts in his name
Fixes #1096 (Encode internet search URLs with spaces as %20 rather than +)
This commit is contained in:
parent
d81c912b07
commit
15c6ee80de
@ -5,7 +5,7 @@
|
|||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
from polyglot.urllib import quote_plus
|
from polyglot.urllib import quote, quote_plus
|
||||||
|
|
||||||
AUTHOR_SEARCHES = {
|
AUTHOR_SEARCHES = {
|
||||||
'goodreads':
|
'goodreads':
|
||||||
@ -48,17 +48,21 @@ all_book_searches = BOOK_SEARCHES.__iter__
|
|||||||
all_author_searches = AUTHOR_SEARCHES.__iter__
|
all_author_searches = AUTHOR_SEARCHES.__iter__
|
||||||
|
|
||||||
|
|
||||||
def qquote(val):
|
def qquote(val, use_plus=True):
|
||||||
if not isinstance(val, bytes):
|
if not isinstance(val, bytes):
|
||||||
val = val.encode('utf-8')
|
val = val.encode('utf-8')
|
||||||
ans = quote_plus(val)
|
ans = quote_plus(val) if use_plus else quote(val)
|
||||||
if isinstance(ans, bytes):
|
if isinstance(ans, bytes):
|
||||||
ans = ans.decode('utf-8')
|
ans = ans.decode('utf-8')
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
def specialised_quote(template, val):
|
||||||
|
return qquote(val, 'goodreads.com' not in template)
|
||||||
|
|
||||||
|
|
||||||
def url_for(template, data):
|
def url_for(template, data):
|
||||||
return template.format(**{k: qquote(v) for k, v in iteritems(data)})
|
return template.format(**{k: specialised_quote(template, v) for k, v in iteritems(data)})
|
||||||
|
|
||||||
|
|
||||||
def url_for_author_search(key, **kw):
|
def url_for_author_search(key, **kw):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user