Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
exclude: ^tests/.+\.html
Expand All @@ -10,18 +10,18 @@ repos:
- id: check-added-large-files
- id: check-toml

- repo: https://github.com/psf/black
rev: 23.11.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.3.1
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 8.0.1
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.3.0
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -34,6 +34,6 @@ repos:
- pep8-naming

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
rev: v1.20.1
hooks:
- id: mypy
20 changes: 8 additions & 12 deletions src/urlstd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1911,28 +1911,24 @@ class URLSearchParams(Collection):
"""

@overload
def __init__(self, init: str) -> None:
...
def __init__(self, init: str) -> None: ...

@overload
def __init__(self, init: Sequence[Sequence[str | int | float]]) -> None:
...
def __init__(
self, init: Sequence[Sequence[str | int | float]]
) -> None: ...

@overload
def __init__(self, init: dict[str, str | int | float]) -> None:
...
def __init__(self, init: dict[str, str | int | float]) -> None: ...

@overload
def __init__(self, init: URLRecord) -> None:
...
def __init__(self, init: URLRecord) -> None: ...

@overload
def __init__(self, init: "URLSearchParams") -> None:
...
def __init__(self, init: "URLSearchParams") -> None: ...

@overload
def __init__(self) -> None:
...
def __init__(self) -> None: ...

def __init__(
self,
Expand Down
16 changes: 8 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ def test_idna_domain_to_ascii_raise_icuerror(caplog, mocker):
def test_idna_domain_to_ascii_use_std3_rules(caplog):
"""Unicode ToASCII: UseSTD3ASCIIRules=true: A domain contains non-LDH ASCII."""
caplog.set_level(logging.INFO)
domain = "a\u2260b\u226Ec\u226Fd"
domain = "a\u2260b\u226ec\u226fd"

assert IDNA.domain_to_ascii(domain) == "xn--abcd-5n9aqdi"
assert len(caplog.record_tuples) == 0
Expand Down Expand Up @@ -1595,7 +1595,7 @@ def test_idna_domain_to_unicode_use_std3_rules(caplog):
caplog.set_level(logging.INFO)

ascii_domain = "xn--abcd-5n9aqdi"
domain = "a\u2260b\u226Ec\u226Fd"
domain = "a\u2260b\u226ec\u226fd"
assert IDNA.domain_to_unicode(ascii_domain) == domain
assert len(caplog.record_tuples) == 0

Expand Down Expand Up @@ -3553,15 +3553,15 @@ def test_urlsearchparams_construct_raise_exception():
def test_urlsearchparams_construct_with_surrogates():
"""URLSearchParams construct with 3 unpaired surrogates (no leading)"""
params = URLSearchParams(
[["x\uDC53", "1"], ["x\uDC53", 2], ["x\uDC53", 3.0]]
[["x\udc53", "1"], ["x\udc53", 2], ["x\udc53", 3.0]]
)
assert len(params) == 3
assert params.get("x\uDC53") == "1"
assert params.get("x\uFFFD") == "1"
assert params.get_all("x\uDC53") == ("1", "2", "3.0")
assert params.get_all("x\uFFFD") == ("1", "2", "3.0")
assert params.get("x\udc53") == "1"
assert params.get("x\ufffd") == "1"
assert params.get_all("x\udc53") == ("1", "2", "3.0")
assert params.get_all("x\ufffd") == ("1", "2", "3.0")

params.delete("x\uFFFD")
params.delete("x\ufffd")
assert len(params) == 0


Expand Down
16 changes: 8 additions & 8 deletions tests/wpt/test_urlencoded_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
"val",
[
{"input": "test", "output": [["test", ""]]},
{"input": "\uFEFFtest=\uFEFF", "output": [["\uFEFFtest", "\uFEFF"]]},
{"input": "\ufefftest=\ufeff", "output": [["\ufefftest", "\ufeff"]]},
{
"input": "%EF%BB%BFtest=%EF%BB%BF",
"output": [["\uFEFFtest", "\uFEFF"]],
"output": [["\ufefftest", "\ufeff"]],
},
{"input": "%EF%BF%BF=%EF%BF%BF", "output": [["\uFFFF", "\uFFFF"]]},
{"input": "%FE%FF", "output": [["\uFFFD\uFFFD", ""]]},
{"input": "%FF%FE", "output": [["\uFFFD\uFFFD", ""]]},
{"input": "%EF%BF%BF=%EF%BF%BF", "output": [["\uffff", "\uffff"]]},
{"input": "%FE%FF", "output": [["\ufffd\ufffd", ""]]},
{"input": "%FF%FE", "output": [["\ufffd\ufffd", ""]]},
{"input": "†&†=x", "output": [["†", ""], ["†", "x"]]},
{"input": "%C2", "output": [["\uFFFD", ""]]},
{"input": "%C2x", "output": [["\uFFFDx", ""]]},
{"input": "%C2", "output": [["\ufffd", ""]]},
{"input": "%C2x", "output": [["\ufffdx", ""]]},
{
"input": "_charset_=windows-1252&test=%C2x",
"output": [["_charset_", "windows-1252"], ["test", "\uFFFDx"]],
"output": [["_charset_", "windows-1252"], ["test", "\ufffdx"]],
},
{"input": "", "output": []},
{"input": "a", "output": [["a", ""]]},
Expand Down
24 changes: 12 additions & 12 deletions tests/wpt/test_urlsearchparams_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,22 @@ def test_parse_percent_encoded_2384():

def test_parse_d83d_dca9():
"""Parse \\uD83D\\uDCA9"""
params = URLSearchParams("a=b\uD83D\uDCA9c")
params = URLSearchParams("a=b\ud83d\udca9c")
# assert params.get("a") == "b\uD83D\uDCA9c", list(params)
# NOTE: "b\uD83D\uDCA9c" and "b\U0001F4A9c" are not equal in Python.
assert params.get("a") == "b\U0001F4A9c", list(params)
params = URLSearchParams("a\uD83D\uDCA9b=c")
assert params.get("a\uD83D\uDCA9b") == "c", list(params)
assert params.get("a") == "b\U0001f4a9c", list(params)
params = URLSearchParams("a\ud83d\udca9b=c")
assert params.get("a\ud83d\udca9b") == "c", list(params)


def test_parse_percent_encoded_d83d_dca9():
"""Parse %f0%9f%92%a9"""
params = URLSearchParams("a=b%f0%9f%92%a9c")
# assert params.get("a") == "b\uD83D\uDCA9c", list(params)
# NOTE: "b\uD83D\uDCA9c" and "b\U0001F4A9c" are not equal in Python.
assert params.get("a") == "b\U0001F4A9c", list(params)
assert params.get("a") == "b\U0001f4a9c", list(params)
params = URLSearchParams("a%f0%9f%92%a9b=c")
assert params.get("a\uD83D\uDCA9b") == "c", list(params)
assert params.get("a\ud83d\udca9b") == "c", list(params)


def test_sequences_of_strings():
Expand Down Expand Up @@ -211,18 +211,18 @@ def test_sequences_of_strings():
"name": "array with two keys",
},
{
"input": {"\uD835x": "1", "xx": "2", "\uD83Dx": "3"},
"output": [["\uFFFDx", "3"], ["xx", "2"]],
"input": {"\ud835x": "1", "xx": "2", "\ud83dx": "3"},
"output": [["\ufffdx", "3"], ["xx", "2"]],
"name": "2 unpaired surrogates (no trailing)",
},
{
"input": {"x\uDC53": "1", "x\uDC5C": "2", "x\uDC65": "3"},
"output": [["x\uFFFD", "3"]],
"input": {"x\udc53": "1", "x\udc5c": "2", "x\udc65": "3"},
"output": [["x\ufffd", "3"]],
"name": "3 unpaired surrogates (no leading)",
},
{
"input": {"a\0b": "42", "c\uD83D": "23", "d\u1234": "foo"},
"output": [["a\0b", "42"], ["c\uFFFD", "23"], ["d\u1234", "foo"]],
"input": {"a\0b": "42", "c\ud83d": "23", "d\u1234": "foo"},
"output": [["a\0b", "42"], ["c\ufffd", "23"], ["d\u1234", "foo"]],
"name": "object with NULL, non-ASCII, and surrogate keys",
},
],
Expand Down
8 changes: 4 additions & 4 deletions tests/wpt/test_urlsearchparams_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
"output": [["a", "b"], ["a", "a"], ["z", "b"], ["z", "a"]],
},
{
"input": "\uFFFD=x&\uFFFC&\uFFFD=a",
"output": [["\uFFFC", ""], ["\uFFFD", "x"], ["\uFFFD", "a"]],
"input": "\ufffd=x&\ufffc&\ufffd=a",
"output": [["\ufffc", ""], ["\ufffd", "x"], ["\ufffd", "a"]],
},
{
"input": "ffi&🌈",
# 🌈 > code point, but < code unit because two code units
"output": [["🌈", ""], ["ffi", ""]],
},
{
"input": "é&e\uFFFD&e\u0301",
"output": [["e\u0301", ""], ["e\uFFFD", ""], ["é", ""]],
"input": "é&e\ufffd&e\u0301",
"output": [["e\u0301", ""], ["e\ufffd", ""], ["é", ""]],
},
{
"input": "z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g",
Expand Down
4 changes: 2 additions & 2 deletions tests/wpt/test_urlsearchparams_stringifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def test_serialize_00():
def test_serialize_d83d_dca9():
"""Serialize \\uD83D\\uDCA9"""
params = URLSearchParams()
params.append("a", "b\uD83D\uDCA9c")
params.append("a", "b\ud83d\udca9c")
assert params + "" == "a=b%F0%9F%92%A9c"
params.delete("a")
params.append("a\uD83D\uDCA9b", "c")
params.append("a\ud83d\udca9b", "c")
assert params + "" == "a%F0%9F%92%A9b=c"


Expand Down
Loading