Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@cached_property
def parent(self):
"""A new URL with last part of path removed and cleaned up query and
fragment.
"""
path = self.raw_path
if not path or path == "/":
if self.raw_fragment or self.raw_query_string:
return URL(self._val._replace(query="", fragment=""), encoded=True)
return self
parts = path.split("/")
val = self._val._replace(path="/".join(parts[:-1]), query="", fragment="")
return URL(val, encoded=True)
@cached_property
def raw_parts(self):
"""A tuple containing encoded *path* parts.
('/',) for absolute URLs if *path* is missing.
"""
path = self._val.path
if self.is_absolute():
if not path:
parts = ["/"]
else:
parts = ["/"] + path[1:].split("/")
else:
if path.startswith("/"):
parts = ["/"] + path[1:].split("/")
else:
@cached_property
def password(self):
"""Decoded password part of URL.
None if password is missing.
"""
return self._UNQUOTER(self.raw_password)
@cached_property
def name(self):
"""The last part of parts."""
return self._UNQUOTER(self.raw_name)
@cached_property
def query_string(self):
"""Decoded query part of URL.
Empty string if query is missing.
"""
return self._QS_UNQUOTER(self.raw_query_string)
@cached_property
def parts(self):
"""A tuple containing decoded *path* parts.
('/',) for absolute URLs if *path* is missing.
"""
return tuple(self._UNQUOTER(part) for part in self.raw_parts)
@cached_property
def user(self):
"""Decoded user part of URL.
None if user is missing.
"""
return self._UNQUOTER(self.raw_user)
@cached_property
def path(self):
"""Decoded path of URL.
/ for absolute URLs without path part.
"""
return self._PATH_UNQUOTER(self.raw_path)
@cached_property
def fragment(self):
"""Decoded fragment part of URL.
Empty string if fragment is missing.
"""
return self._UNQUOTER(self.raw_fragment)
@cached_property
def host(self):
"""Decoded host part of URL.
None for relative URLs.
"""
raw = self.raw_host
if raw is None:
return None
if "%" in raw:
# Hack for scoped IPv6 addresses like
# fe80::2%Проверка
# presence of '%' sign means only IPv6 address, so idna is useless.
return raw
try:
return idna.decode(raw.encode("ascii"))