コード例 #1
0
ファイル: gui_client.py プロジェクト: zypangpang/mymdict
def test_client():
    q=QUrl("entry: abc")
    print(q.toString().split(":")[1].strip("/ "))
    print(q.scheme())
    print(q.host())
    print(q.path())
    print(q.fragment())
コード例 #2
0
 def _on_highlighted(self, url: QUrl) -> None:
     """ In general, if the mouse has moved over a new hyperlink, we save the fragment and send a mouseover action.
         An empty URL is given when the mouse moves off a hyperlink, which counts as a deselection.
         However, mouseovers are error-prone; there are unavoidable breaks between characters in a column.
         To avoid twitchy selection/deselection, we only send mouseover signals when the reference isn't empty. """
     self._ref = ref = url.fragment()
     if ref and not self._has_focus:
         self._select()
コード例 #3
0
def qute_back(url: QUrl) -> _HandlerRet:
    """Handler for qute://back.

    Simple page to free ram / lazy load a site, goes back on focusing the tab.
    """
    src = jinja.render(
        'back.html',
        title='Suspended: ' + urllib.parse.unquote(url.fragment()))
    return 'text/html', src
コード例 #4
0
def parse_javascript_url(url: QUrl) -> str:
    """Get JavaScript source from the given URL.

    See https://wiki.whatwg.org/wiki/URL_schemes#javascript:_URLs
    and https://github.com/whatwg/url/issues/385
    """
    ensure_valid(url)
    if url.scheme() != 'javascript':
        raise Error("Expected a javascript:... URL")
    if url.authority():
        raise Error("URL contains unexpected components: {}".format(
            url.authority()))

    code = url.path(QUrl.FullyDecoded)
    if url.hasQuery():
        code += '?' + url.query(QUrl.FullyDecoded)
    if url.hasFragment():
        code += '#' + url.fragment(QUrl.FullyDecoded)

    if not code:
        raise Error("Resulted in empty JavaScript code")

    return code
コード例 #5
0
 def _send_action(self, url: QUrl) -> None:
     """ Call back with the fragment string of the URL under the cursor and the focus state. """
     self._call_on_graph_action(url.fragment(), self._has_focus)
コード例 #6
0
    def url_watcher(self, url: QtCore.QUrl):
        """Watches the QWebEngineView for url changes."""
        if url.host() not in [
                'twitch.tv', 'localhost',
                self.ENDPOINT.host(), 'passport.twitch.tv'
        ] and url.host() != '':

            self.LOGGER.warning(
                f'Redirected to an unsupported host!  ({url.host()})')

            self.LOGGER.debug('Creating informative dialog...')
            _m = QtWidgets.QMessageBox(
                QtWidgets.QMessageBox.Critical, 'Token Generator',
                f'You were redirected to an unsupported host.  ({url.host()})',
                QtWidgets.QMessageBox.Ok, self)

            self.LOGGER.debug('Displaying dialog...')
            self.hide()
            _m.exec()

            self.LOGGER.debug('Ensuring dialog is deleted properly...')
            if not sip.isdeleted(_m):
                _m.deleteLater()

            self.browser.setUrl(QtCore.QUrl('about:blank'))
            return self.reject()

        if url.hasFragment():
            query = QtCore.QUrlQuery(url.fragment())

        else:
            query = QtCore.QUrlQuery(url.query())

        if not query.hasQueryItem('state') and url.path() != '/two_factor/new':
            self.LOGGER.warning('No state sent!')

            self.LOGGER.debug('Creating informative dialog...')
            _m = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical,
                                       'Token Generator',
                                       "The state parameter wasn't passed.",
                                       QtWidgets.QMessageBox.Ok, self)

            self.LOGGER.debug('Displaying dialog...')
            self.hide()
            _m.exec()

            self.LOGGER.debug('Ensuring dialog is deleted properly...')
            if not sip.isdeleted(_m):
                _m.deleteLater()

            self.browser.setUrl(QtCore.QUrl('about:blank'))
            return self.reject()

        if query.hasQueryItem(
                'state') and self._state != query.queryItemValue('state'):
            self.LOGGER.warning('Sent state is not our state!')

            self.LOGGER.debug('Creating informative dialog...')
            _m = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical,
                                       'Token Generator',
                                       'Sent state is not our state.',
                                       QtWidgets.QMessageBox.Ok, self)

            self.LOGGER.debug('Displaying dialog...')
            _m.exec()
            self.hide()

            self.LOGGER.debug('Ensuring dialog is deleted properly...')
            if not sip.isdeleted(_m):
                _m.deleteLater()

            self.browser.setUrl(QtCore.QUrl('about:blank'))
            return self.reject()

        if query.hasQueryItem('access_token'):
            # Declarations
            app: QtWidgets.QApplication = QtWidgets.QApplication.instance()
            client_id = app.client.settings['extensions']['twitch'][
                'client_id'].value
            scopes: typing.List[Scopes] = [
                Scopes(s) for s in parse.unquote(query.queryItemValue(
                    'scope')).split('+')
            ]

            self.GENERATED.emit(
                token.Token(client_id, query.queryItemValue('access_token'),
                            scopes))
            self.accept()