Skip to content

Commit

Permalink
use yarl for quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Dec 5, 2024
1 parent baa2f1b commit b68ca14
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
if TYPE_CHECKING:
from datetime import datetime
from typing import BinaryIO
from urllib import parse

import httpx
import pytz
Expand Down Expand Up @@ -75,15 +74,7 @@

def quote_url(url: str) -> str:
"""Quote URL args for modern ERDDAP servers."""
# No idea why csv must be quoted in 2.23 but ncCF doesn't :-/
do_not_quote = ["/erddap/search/", "ncCF"]
if any(True for string in do_not_quote if string in url):
return url
# We should always quote some queries.
if "?" in url:
base, unquoted = url.split("?")
url = f"{base}?{parse.quote_plus(unquoted)}"
return url
return str(URL(url))


def _sort_url(url: str) -> str:
Expand All @@ -93,6 +84,15 @@ def _sort_url(url: str) -> str:
params without a value, and sort them.
xref.: https://github.com/aio-libs/yarl/issues/307
Other fixes:
ERDDAP separates variables from constrantains,
query without values from query with values, using &.
That means we need a & before the constranints when there are no variables.
We also strip = and ? from URLs ending. The first is due to yarl issue 307,
the second is harmless but we want to be able to have the same hash
for URLs that will give the same response, so we remove it from all URLs.
"""
replace = ("?", "?&")
sorted_variables = None
Expand Down

0 comments on commit b68ca14

Please sign in to comment.