コード例 #1
0
def toggle_load_fonts(prefix):
    """ Inverts a value, toggling between filtering or not the requests for
    web fonts on the net manager level

    TOG03

    """

    netmanager = get_manager(prefix)
    netmanager.load_webfonts ^= True
    if netmanager.load_webfonts:
        print("---- LOADING WEB FONTS NOW ----")
    else:
        print("---- DISABLING WEB FONTS ----")
コード例 #2
0
def toggle_show_logs(prefix):
    """ Inverts a value, toggling between printing or not responses that were
    accepted by the webkit or (some of) those that were filtered at some point.

    TOG02

    """

    netmanager = get_manager(prefix)
    netmanager.show_detail ^= True
    if netmanager.show_detail:
        print("---- SHOWING DETAILS ----")
    else:
        print("---- HIDING DETAILS ----")
コード例 #3
0
    def navigate(self, request=None):
        """ Open the url on this tab. If 'url' is already a QUrl
        (if it comes from a href click), just send it. Otherwise,
        it comes either from the address bar or the PRIMARY
        clipboard through a keyboard shortcut.
        Check if the "url" is actually one, partial or otherwise;
        if it's not, construct a web search.

        BRW01

        """

        if isinstance(request, QUrl):
            qurl = request

        # 'navigate' was connected to a QLineEdit to extract its text
        elif isinstance(request, QLineEdit):
            url = request.text()
            qurl = fix_url(url)  # BRW11
        else:
            raise RuntimeError("Navigating to non-navigable")

        # if the qurl does not trigger an URL in SHORTENERS or REDIRECTORS,
        # this will be a no-op
        qurl = do_redirect(qurl)  # BRW12

        if self.attr.prefix is None:
            # this is the first navigation on this tab/webkit; replace
            # the Network Access Manager CFG02

            instance = extract_instance(qurl.toString())
            self.attr.set_prefix(get_options()['sites'][instance]['prefix'])

            if self.attr.prefix is None:
                raise RuntimeError(
                    "prefix failed to be set... 'options' is broken")

            # strictly speaking, this should emit from Attributes.set_prefix
            self.set_prefix.emit(self.attr.prefix)
            if self.attr.prefix == "":
                print("GENERAL")
            else:
                print("INSTANCE: {}".format(self.attr.prefix))

            if not has_manager(self.attr.prefix):
                register_manager(self.attr.prefix,
                                 InterceptNAM(instance,
                                              parent=None))

            if not has_manager(self.attr.prefix):
                raise RuntimeError("prefix manager not registered...")

            self.page().setNetworkAccessManager(get_manager(self.attr.prefix))

        print("{}>>>\t\t{}\n>>> NAVIGATE {}{}".format(
            Fore.CYAN,
            datetime.datetime.now().isoformat(),
            qurl.toString(),
            Fore.RESET))

        self.setFocus()
        self.load_requested.emit(qurl.toString())
        self.load(qurl)