def download(self, url, dest=None): """Download a given URL, given as string. Args: url: The URL to download dest: The file path to write the download to, or None to ask. """ url = urlutils.qurl_from_user_input(url) urlutils.raise_cmdexc_if_invalid(url) self.get(url, filename=dest)
def download(self, url=None, dest=None): """Download a given URL, or current page if no URL given. Args: url: The URL to download. If not given, download the current page. dest: The file path to write the download to, or None to ask. """ download_manager = objreg.get('download-manager', scope='window', window=self._win_id) if url: url = urlutils.qurl_from_user_input(url) urlutils.raise_cmdexc_if_invalid(url) download_manager.get(url, filename=dest) else: page = self._current_widget().page() download_manager.get(self._current_url(), page)
def test_raise_cmdexc_if_invalid(url, valid, has_err_string): """Test raise_cmdexc_if_invalid. Args: url: The URL to check. valid: Whether the QUrl is valid (isValid() == True). has_err_string: Whether the QUrl is expected to have errorString set. """ qurl = QUrl(url) assert qurl.isValid() == valid if valid: urlutils.raise_cmdexc_if_invalid(qurl) else: assert bool(qurl.errorString()) == has_err_string if has_err_string: expected_text = "Invalid URL - " + qurl.errorString() else: expected_text = "Invalid URL" with pytest.raises(cmdutils.CommandError, match=expected_text): urlutils.raise_cmdexc_if_invalid(qurl)
def test_raise_cmdexc_if_invalid(url, valid, has_err_string): """Test raise_cmdexc_if_invalid. Args: url: The URL to check. valid: Whether the QUrl is valid (isValid() == True). has_err_string: Whether the QUrl is expected to have errorString set. """ qurl = QUrl(url) assert qurl.isValid() == valid if valid: urlutils.raise_cmdexc_if_invalid(qurl) else: assert bool(qurl.errorString()) == has_err_string if has_err_string: expected_text = "Invalid URL - " + qurl.errorString() else: expected_text = "Invalid URL" with pytest.raises(cmdexc.CommandError, match=expected_text): urlutils.raise_cmdexc_if_invalid(qurl)
def _open(self, url, tab, background, window): """Helper function to open a page. Args: url: The URL to open as QUrl. tab: Whether to open in a new tab. background: Whether to open in the background. window: Whether to open in a new window """ urlutils.raise_cmdexc_if_invalid(url) tabbed_browser = self._tabbed_browser() cmdutils.check_exclusive((tab, background, window), 'tbw') if window: tabbed_browser = self._tabbed_browser(window=True) tabbed_browser.tabopen(url) elif tab: tabbed_browser.tabopen(url, background=False, explicit=True) elif background: tabbed_browser.tabopen(url, background=True, explicit=True) else: widget = self._current_widget() widget.openurl(url)