-
Notifications
You must be signed in to change notification settings - Fork 11
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
Reduce url re-encoding #314
Conversation
@@ -110,9 +110,9 @@ def __init__( | |||
|
|||
# Build variables | |||
if use_https: | |||
self._base_url = f"https://{dsm_ip}:{dsm_port}" | |||
self._base_url = URL(f"https://{dsm_ip}:{dsm_port}") |
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.
By building this here we avoid calling _make_netloc
on every request which has to make an ip_address object and than convert it back to a string
This works fine on my system, but I don't really have a good way to test the encoding is preserved like #261 |
it was initially added with #260 to fix home-assistant/core#87457 |
import yarl
from urllib.parse import urlencode, quote
params = {'user': 'with spaces'}
query = urlencode(params, safe="?/:@-._~!$'()*,", quote_via=quote)
url = yarl.URL('http://example.com')
url_encoded = url.join(yarl.URL(f"?{query}", encoded=True))
print(url_encoded)
print (url_encoded.query)
|
behavior is the same as
|
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.
LGTM, thanks @bdraco 👍
No description provided.