How to use the hyperlink.URL 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_includes_list_of_filtered_tags():
    html_soup = get_html_soup(
        req_url=hyperlink.URL.from_text("http://localhost:1234/?tag=alfa&tag=bravo"),
        tag_query=["alfa", "bravo"]
    )

    alert_div = html_soup.find("div", attrs={"class": ["alert", "tag_query"]})
    actual_text = re.sub(r"\s+", " ", alert_div.text.strip())

    expected_text = "Filtering to documents tagged with alfa x bravo x"

    assert actual_text == expected_text

    links = {
        a_tag.attrs["id"].split(":")[1]: a_tag.attrs["href"]
        for a_tag in alert_div.find_all("a")
    }

    assert links == {
github abilian / abilian-core / abilian / testing / util.py View on Github external
def path_from_url(url):
    url = str(url)
    return "/" + "/".join(URL.from_text(url).path)
github twisted / twisted / src / twisted / python / urlpath.py View on Github external
def _reconstitute(self):
        """
        Reconstitute this L{URLPath} from all its given attributes.
        """
        urltext = urlquote(
            urlparse.urlunsplit((self._scheme, self._netloc,
                                 self._path, self._query, self._fragment)),
            safe=_allascii
        )
        self._url = _URL.fromText(urltext.encode("ascii").decode("ascii"))
github twisted / twisted / src / twisted / python / urlpath.py View on Github external
Reconstruct all the public instance variables of this L{URLPath} from
        its underlying L{_URL}.

        @param urlInstance: the object to base this L{URLPath} on.
        @type urlInstance: L{_URL}

        @return: a new L{URLPath}
        """
        self = cls.__new__(cls)
        self._url = urlInstance.replace(path=urlInstance.path or [u""])
        self._scheme = self._url.scheme.encode("ascii")
        self._netloc = self._url.authority().encode("ascii")
        self._path = (_URL(path=self._url.path,
                           rooted=True).asURI().asText()
                      .encode("ascii"))
        self._query = (_URL(query=self._url.query).asURI().asText()
                       .encode("ascii"))[1:]
        self._fragment = self._url.fragment.encode("ascii")
        return self
github praekeltfoundation / seaworthy / seaworthy / client.py View on Github external
:param port:
            The port for the host to connect to.
        :param dict url_defaults:
            Parameters to default to in the generated URLs, see
            `~hyperlink.URL`.
        :param session:
            A Requests' Session object (or something like it).
        """
        if session is None:
            session = requests.Session()
        self._session = session

        _url_defaults = self.URL_DEFAULTS.copy()
        if url_defaults is not None:
            _url_defaults.update(url_defaults)
        self._base_url = hyperlink.URL(
            host=host, port=int(port), **_url_defaults)
github alexwlchan / docstore / src / api.py View on Github external
def upload_document():
            resp, status_code = self._upload_document()

            if status_code != 201:
                return jsonify(resp), status_code

            # If the request came through the browser rather than via
            # a script, redirect back to the original page (which we get
            # in the "referer" header), along with a message to display.
            try:
                url = hyperlink.URL.from_text(request.headers["referer"])

                for key, value in resp.items():
                    url = url.add(f"_message.{key}", value)

                return redirect(location=str(url))
            except KeyError:
                pass

            return jsonify(resp), 201
github burningmantech / ranger-ims-server / src / ims / application / _auth.py View on Github external
if password is None:
                return invalidQueryResponse(request, "password")

            authenticated = await self.config.authProvider.verifyPassword(
                user, password
            )

            if authenticated:
                session = request.getSession()
                session.user = user

                url = queryValue(request, "o")
                if url is None:
                    location = URLs.app  # Default to application home
                else:
                    location = URL.fromText(url)

                return redirect(request, location)
            else:
                self._log.debug(
                    "Login failed: incorrect credentials for user: {user}",
                    user=user,
                )

        return self.login(request, failed=True)

hyperlink

A featureful, immutable, and correct URL for Python.

MIT
Latest version published 3 years ago

Package Health Score

76 / 100
Full package analysis