View Single Post
Old 08-22-2011, 03:44 AM   #94
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,731
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
I only mentioned safe_formatter because the user said the problem occurred only when they upgraded to the latest version. The latest version only had a one line change of the import statement from the old safe_formatter that got deleted to the new one. Perhaps the user was wrong and this was always broken for this particular scenario, or perhaps there has been some other change to Qt. Or perhaps they were on a REALLY old version of this plugin.

I should have posted extra lines to give more info. The reason I use QUrl.fromEncoded is because the Url is not exactly like how I posted. Instead there are two further complications:

(1) The url may contain quotes as part of it's template specification, encoded as %22
Code:
http://www.google.com/#sclient=psy&q=%22{author}%22+%22{title}%22
(2) The text being injected into the template by safe_format gets "encoded" usually with utf-8 but for some websites like Amazon it is latin-1:
Code:
text = quote_plus(text.encode(encoding, 'ignore'))
Now the original way I had of opening urls (using webbrowser.open(url) rather than using Calibre's open_url function) coped with all of this perfectly fine. Then many months ago when I changed to use Calibre's open_url due to someone reporting a problem on some flavour of linux, I found that I could not just do open_url(QUrl(url)) because the %22 stuff does not translate.

So instead I was using QUrl.fromEncoding(url) - which solves the %22 stuff but apparently will barf on the other "encoded" foreign characters...

Last edited by kiwidude; 08-22-2011 at 04:09 AM.
kiwidude is offline   Reply With Quote