-
Notifications
You must be signed in to change notification settings - Fork 1.3k
import-url: allow queries in URL #3432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
48495d0
84e41d5
650c2b4
dd4d090
ca2d90f
4031ab0
b6d7930
6e325d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,3 +241,79 @@ class CloudURLInfo(URLInfo): | |
| @property | ||
| def path(self): | ||
| return self._spath.lstrip("/") | ||
|
|
||
|
|
||
| class HTTPURLInfo(URLInfo): | ||
| def __init__(self, url): | ||
| p = urlparse(url) | ||
| stripped = p._replace(params=None, query=None, fragment=None) | ||
| super().__init__(stripped.geturl()) | ||
| self.params = p.params | ||
| self.query = p.query | ||
| self.fragment = p.fragment | ||
|
|
||
| @classmethod | ||
| def from_parts( | ||
| cls, | ||
| scheme=None, | ||
| host=None, | ||
| user=None, | ||
| port=None, | ||
| path="", | ||
| netloc=None, | ||
| params=None, | ||
| query=None, | ||
| fragment=None, | ||
| ): | ||
| assert bool(host) ^ bool(netloc) | ||
|
|
||
| if netloc is not None: | ||
| return cls( | ||
| "{}://{}{}{}{}{}".format( | ||
| scheme, | ||
| netloc, | ||
| path, | ||
| (";" + params) if params else "", | ||
| ("?" + query) if query else "", | ||
| ("#" + fragment) if fragment else "", | ||
| ) | ||
| ) | ||
|
|
||
| obj = cls.__new__(cls) | ||
| obj.fill_parts(scheme, host, user, port, path) | ||
| obj.params = params | ||
| obj.query = query | ||
| obj.fragment = fragment | ||
|
Comment on lines
+283
to
+286
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't bother overriding
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then don't. It used via
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You keep saying don't need to override, but you override. Not sure I understand what you are up to here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean technically the correct way to do things would be: def fill_parts(self, scheme, host, user, port, path, params, query, fragment):
super().fill_parts(self, scheme, host, user, port, path)
self.params = params
self.query = query
self.fragment = fragmentbut this isn't required right now as |
||
| return obj | ||
|
|
||
| @property | ||
| def _extra_parts(self): | ||
| return (self.params, self.query, self.fragment) | ||
|
|
||
| @property | ||
| def parts(self): | ||
| return self._base_parts + self._path.parts + self._extra_parts | ||
|
|
||
| @cached_property | ||
| def url(self): | ||
| return "{}://{}{}{}{}{}".format( | ||
| self.scheme, | ||
| self.netloc, | ||
| self._spath, | ||
| (";" + self.params) if self.params else "", | ||
| ("?" + self.query) if self.query else "", | ||
| ("#" + self.fragment) if self.fragment else "", | ||
| ) | ||
|
|
||
| def __eq__(self, other): | ||
| if isinstance(other, (str, bytes)): | ||
| other = self.__class__(other) | ||
| return ( | ||
| self.__class__ == other.__class__ | ||
| and self._base_parts == other._base_parts | ||
| and self._path == other._path | ||
| and self._extra_parts == other._extra_parts | ||
| ) | ||
|
|
||
| def __hash__(self): | ||
| return hash(self.parts) | ||
casperdcl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we use restringification? May use
.from_parts()or.fill_parts().Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More future-proof to use
super()to use the parent's logic. Otherwise we'd needand not call
super(), which is allowed but not great practice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, we can ignore all of this as long as it works. Some tech debt, but might be resolved later.
Needing to parse, restringify and parse is a kludge.