How to use the hyperlink.URL.from_text function in hyperlink

To help you get started, we’ve selected a few hyperlink examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexwlchan / docstore / tests / test_viewer.py View on Github external
def test_next_page_link(self, req_url, expected_url):
        html_soup = get_html_soup(
            pagination=Pagination(
                page_size=25,
                current_page=4,
                total_documents=200
            ),
            req_url=hyperlink.URL.from_text(req_url)
        )

        pagination_div = html_soup.find("nav", attrs={"id": "pagination"})
        next_li = pagination_div.find("li", attrs={"id": "pagination__next"})
        assert next_li.find("a").attrs["href"] == expected_url
github alexwlchan / docstore / tests / test_viewer.py View on Github external
def test_prev_page_link_on_page_1(self, req_url, expected_url):
        html_soup = get_html_soup(
            pagination=Pagination(
                page_size=25,
                current_page=2,
                total_documents=50
            ),
            req_url=hyperlink.URL.from_text(req_url)
        )

        pagination_div = html_soup.find("nav", attrs={"id": "pagination"})
        prev_li = pagination_div.find("li", attrs={"id": "pagination__prev"})
        assert prev_li.find("a").attrs["href"] == expected_url
github alexwlchan / docstore / tests / test_viewer.py View on Github external
def assert_query_param_equal(query1, query2):
        assert (
            sorted(hyperlink.URL.from_text(query1).query) ==
            sorted(hyperlink.URL.from_text(query2).query)
        )
github alexwlchan / docstore / tests / test_viewer.py View on Github external
def test_removes_page_pagesize_in_document_tags(self, document):
        document["tags"] = ["alfa", "bravo"]
        html_soup = get_html_soup(
            documents=[(1, document)],
            req_url=hyperlink.URL.from_text("http://localhost:1234?page=4")
        )

        document_tags = html_soup.find(
            "div", attrs={"class": "document__metadata__tags"})
        links = [a_tag.attrs["href"] for a_tag in document_tags.find_all("a")]

        assert links == [
            "?tag=alfa",
            "?tag=bravo",
        ]
github alexwlchan / docstore / tests / test_multilevel_tag_list.py View on Github external
def test_can_render_tag_counter(tag_counter):  # pragma: no cover
    req_url = hyperlink.URL.from_text("http://localhost:1234/")

    html = render_tags(req_url=req_url, tag_counter=tag_counter)

    assert html.count("<ul>") == html.count("</ul>")
    assert html.count("<li>") == html.count("</li>")
    assert html.count("<a>")
    assert html.count("<span span="">")
</span></a>
github alexwlchan / docstore / tests / test_viewer.py View on Github external
def test_preserves_other_query_params_setting_sort_option(self):
        html_soup = get_html_soup(
            req_url=hyperlink.URL.from_text(
                "http://localhost:1234?tag=x&tag=y"
            )
        )

        expected = {
            "title (a-z)": "?tag=x&tag=y&sort=title:a_z",
            "title (z-a)": "?tag=x&tag=y&sort=title:z_a",
            "date created (newest first)": "?tag=x&tag=y&sort=date_created:newest_first",
            "date created (oldest first)": "?tag=x&tag=y&sort=date_created:oldest_first",
        }

        for label, url in self.get_sort_options(html_soup).items():
            self.assert_query_param_equal(url, expected[label])
github mahmoud / chert / chert / hypertext.py View on Github external
% mode)
    for el in html_tree.iter():
        if not isinstance(el.tag, basestring):
            continue
        if not el.tag == 'a':
            continue
        if el.get('target'):
            continue  # let explicit settings lie
        href = el.get('href')
        if not href or href.startswith('#'):
            continue
        if mode == 'all':
            retarget = True
        elif mode == 'external':
            try:
                url = URL.from_text(href)
            except ValueError:
                retarget = True
            else:
                retarget = bool(url.host)
        if retarget:
            el.set('target', '_blank')
            el.set('rel', 'noopener')
    return
github genomoncology / rigor / src / rigor / swagger.py View on Github external
def path_as_tuple(cls, url):
        """ Convert URL path into a set of tuples replacing variables. """

        # remove leading and trailing blanks
        items = hyperlink.URL.from_text(url).path
        items = items[1:] if items and not items[0] else items
        items = items[:-1] if items and not items[-1] else items

        # replace variables with VAR indicator for resolve
        return tuple([VAR if cls.is_var(item) else item for item in items])
github zeroSteiner / protocon / lib / protocon / engine.py View on Github external
def from_url(cls, url, plugins=None, **kwargs):
		if plugins is None:
			plugins = plugin_manager.PluginManager()
		elif not isinstance(plugins, plugin_manager.PluginManager):
			raise TypeError('plugins must be an instance of PluginManager')

		if isinstance(url, str):
			url = hyperlink.URL.from_text(url)
		scheme_count = sum([len(driver.schemes) for driver in plugins.connection_drivers.values()])
		color.print_status("Loaded {:,} connection drivers, providing {:,} URL schemes".format(len(plugins.connection_drivers), scheme_count))
		if plugins.transcoders:
			color.print_status("Loaded {0:,} transcode drivers".format(len(plugins.transcoders)))
		driver = next((driver for driver in plugins.connection_drivers.values() if url.scheme in driver.schemes), None)
		if driver is None:
			raise errors.ProtoconDriverError('no connection driver for scheme: ' + url.scheme)

		driver = driver(url)
		return cls(driver, plugins=plugins, **kwargs)

hyperlink

A featureful, immutable, and correct URL for Python.

MIT
Latest version published 4 years ago

Package Health Score

73 / 100
Full package analysis