Skip to content

Commit

Permalink
handle origin already
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Oct 17, 2024
1 parent 6c34a02 commit 3ae3f31
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,16 @@ def _origin(self) -> "URL":
user, password, path, query and fragment are removed.
"""
if not (netloc := self._val.netloc):
scheme, netloc, path, query, fragment = self._val
if not netloc:
raise ValueError("URL should be absolute")
if not (scheme := self._val.scheme):
if not scheme:
raise ValueError("URL should have scheme")
if "@" in netloc:
encoded_host = self.host_subcomponent
netloc = self._make_netloc(None, None, encoded_host, self.explicit_port)
elif not path and not query and not fragment:
return self
return self._from_val(tuple.__new__(SplitResult, (scheme, netloc, "", "", "")))

def relative(self) -> "URL":
Expand Down

0 comments on commit 3ae3f31

Please sign in to comment.