Package: sphinx Version: 1.3.5-1 Severity: normal Tags: patch User: ubuntu-de...@lists.ubuntu.com Usertags: origin-ubuntu xenial ubuntu-patch
Hiya, Here's a diff to port the jstest from webkit1 to 2 - I wanted this for Ubuntu since sphinx is in main there and we're trying to move over to wk2. Apparently (according to upstream) you can get the return value from executed javascript, so the title hack ought not to be necessary any more - but I didn't manage to get this working. It's a bit fiddly to access. If you want to improve the patch to do that, please do. :) Cheers, -- Iain Lane [ i...@orangesquash.org.uk ] Debian Developer [ la...@debian.org ] Ubuntu Developer [ la...@ubuntu.com ]
diff -Nru sphinx-1.3.5/debian/control sphinx-1.3.5/debian/control --- sphinx-1.3.5/debian/control 2016-01-26 11:28:04.000000000 +0000 +++ sphinx-1.3.5/debian/control 2016-02-08 16:09:48.000000000 +0000 @@ -20,7 +20,7 @@ python-sphinx-rtd-theme, python3-sphinx-rtd-theme, python-alabaster (>= 0.7), python3-alabaster (>= 0.7), xvfb, xauth, libjs-jquery (>= 1.4), libjs-underscore, - python3-gi, gir1.2-webkit-3.0, + python3-gi, gir1.2-webkit2-4.0, texlive-latex-recommended, texlive-latex-extra, texlive-fonts-recommended, texinfo, perl X-Python-Version: >= 2.6 diff -Nru sphinx-1.3.5/debian/jstest/jstest.py sphinx-1.3.5/debian/jstest/jstest.py --- sphinx-1.3.5/debian/jstest/jstest.py 2016-01-26 11:27:53.000000000 +0000 +++ sphinx-1.3.5/debian/jstest/jstest.py 2016-02-08 18:10:58.000000000 +0000 @@ -34,11 +34,10 @@ import gi gi.require_version('Gtk', '3.0') -gi.require_version('WebKit', '3.0') -from gi.repository import GLib, Gtk, WebKit +gi.require_version('WebKit2', '4.0') +from gi.repository import GLib, Gtk, WebKit2 -default_time_limit = 10.0 -time_step = 0.1 +default_time_limit = 40.0 # HTTP browser # ============ @@ -49,45 +48,43 @@ class Browser(object): def __init__(self, options): - settings = WebKit.WebSettings() - settings.set_property('enable-file-access-from-file-uris', True) + settings = WebKit2.Settings() + settings.set_property('allow-file-access-from-file-urls', True) self._time_limit = 0 - self._view = WebKit.WebView() - self._view.set_settings(settings) + self._view = WebKit2.WebView.new_with_settings(settings) + self._view.connect('notify::title', self._on_title_changed) self._result = None + self._id = 0 + + def _on_title_changed(self, webview, user_data): + contents = webview.get_property('title') + webview.run_javascript('document.title = ""') + found = "Search finished" in contents + if found: + self._result = contents + Gtk.main_quit() + GLib.source_remove(self._id) + self._id = 0 + + def _quit(self): + self._view.run_javascript('document.title = document.documentElement.innerHTML') + if self._time_limit < 0: + self._result = None + Gtk.main_quit() + return GLib.SOURCE_REMOVE + + self._time_limit -= 1 + return GLib.SOURCE_CONTINUE def wget(self, url, time_limit=default_time_limit): self._view.load_uri(url) self._time_limit = time_limit - GLib.timeout_add(int(1000 * time_step), self._check) + self._id = GLib.timeout_add_seconds(time_limit, self._quit) Gtk.main() if self._result is None: raise Timeout return self._result - def _extract_html(self): - # There is not obvious way to extract HTML from WebKit. - # We use a trick from <http://code.google.com/p/pywebkitgtk/wiki/HowDoI> instead. - self._view.execute_script('document.title = document.documentElement.innerHTML') - try: - return self._view.get_main_frame().get_title() or '' - finally: - self._view.execute_script('document.title = ""') - - def _check(self): - contents = self._extract_html() - match = re_done.search(contents) - if match is not None: - self._result = contents - Gtk.main_quit() - return - self._time_limit -= time_step - if self._time_limit < 0: - self._result = None - Gtk.main_quit() - else: - GLib.timeout_add(int(1000 * time_step), self._check) - # Actual tests # ============ @@ -127,6 +124,7 @@ def test_directory(directory, options, time_limit=default_time_limit): url = urllib.parse.urljoin('file:', urllib.request.pathname2url(directory)) url = urllib.parse.urljoin(url, 'html/search.html?q=' + urllib.parse.quote_plus(options.search_term)) + browser = Browser(options) html = browser.wget(url, time_limit) return test_html(html, options)