Skip to content

Commit

Permalink
Added option for treating URL as url-encoded
Browse files Browse the repository at this point in the history
It fixes errors with non-ascii url-encoded URls
  • Loading branch information
ventura committed Sep 13, 2012
1 parent 614c2fb commit 11c28dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions scripts/webkit2png
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ if __name__ == '__main__':
help="Render output on a transparent background (Be sure to have a transparent background defined in the html)", default=False)
parser.add_option("", "--style", dest="style",
help="Change the Qt look and feel to STYLE (e.G. 'windows').", metavar="STYLE")
parser.add_option("", "--encoded-url", dest="encoded_url", action="store_true",
help="Treat URL as url-encoded", metavar="ENCODED_URL", default=False)
parser.add_option("-d", "--display", dest="display",
help="Connect to X server at DISPLAY.", metavar="DISPLAY")
parser.add_option("--debug", action="store_true", dest="debug",
Expand Down Expand Up @@ -181,6 +183,7 @@ if __name__ == '__main__':
renderer.format = options.format
renderer.grabWholeWindow = options.window
renderer.renderTransparentBackground = options.transparent
renderer.encodedUrl = options.encoded_url

if options.scale:
renderer.scaleRatio = options.ratio
Expand Down
9 changes: 5 additions & 4 deletions webkit2png/webkit2png.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(self,**kwargs):
self.ignoreConfirm = kwargs.get('ignoreConfirm', True)
self.ignorePrompt = kwargs.get('ignorePrompt', True)
self.interruptJavaScript = kwargs.get('interruptJavaScript', True)
self.encodedUrl = kwargs.get('encodedUrl', False)

# Set some default options for QWebPage
self.qWebSettings = {
Expand Down Expand Up @@ -264,10 +265,10 @@ def _load_page(self, url, width, height, timeout):
cancelAt = time.time() + timeout
self.__loading = True
self.__loadingResult = False # Default
# TODO: fromEncoded() needs to be used in some situations. Some
# sort of flag should be passed in to WebkitRenderer maybe?
#self._page.mainFrame().load(QUrl.fromEncoded(url))
self._page.mainFrame().load(QUrl(url))
if self.encodedUrl:
self._page.mainFrame().load(QUrl.fromEncoded(url))
else:
self._page.mainFrame().load(QUrl(url))
while self.__loading:
if timeout > 0 and time.time() >= cancelAt:
raise RuntimeError("Request timed out on %s" % url)
Expand Down

0 comments on commit 11c28dd

Please sign in to comment.