Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 == {
def path_from_url(url):
url = str(url)
return "/" + "/".join(URL.from_text(url).path)
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"))
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
: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)
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
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)