Skip to content
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

Make positional only args kwargs or positional #18

Merged
merged 2 commits into from
Jul 20, 2023
Merged
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
2 changes: 1 addition & 1 deletion fast_query_parsers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Returns:
A list of string/string tuples.
"""

def parse_url_encoded_dict(qs: bytes, parse_numbers: bool) -> dict[str, Any]: ...
def parse_url_encoded_dict(qs: bytes, parse_numbers: bool = False) -> dict[str, Any]: ...

"""Parse a query string into a dictionary of values.

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ pub use query_string::{parse_query_string as parse_qs, parse_query_string_to_jso

// parse query string into a list of tuples.
#[pyfunction]
#[pyo3(text_signature = "(qs, separator, /)")]
#[pyo3(text_signature = "(qs, separator)")]
fn parse_query_string(qs: &[u8], separator: char) -> PyResult<Vec<(String, String)>> {
Ok(parse_qs(qs, separator))
}

// parse query string into a python object.
#[pyfunction]
#[pyo3(signature = (qs, parse_numbers=true, /),text_signature = "(qs, parse_numbers=true, /)")]
#[pyo3(signature = (qs, parse_numbers=true),text_signature = "(qs, parse_numbers=true)")]
fn parse_url_encoded_dict(py: Python, qs: &[u8], parse_numbers: bool) -> PyResult<PyObject> {
Ok(pythonize(py, &parse_query_string_to_json(qs, parse_numbers)).unwrap())
}
Expand Down
13 changes: 13 additions & 0 deletions tests/test_parse_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,16 @@ def test_parse_urlencoded_defaults_parse_numbers_true() -> None:
"polluting": False,
"json": None,
}


def test_parse_urlencoded_kwargs() -> None:
result = parse_url_encoded_dict(qs=encoded, parse_numbers=True)
assert result == {
"value": [10, 12],
"veggies": ["tomato", "potato", "aubergine"],
"nested": {"some_key": "some_value"},
"calories": 122.53,
"healthy": True,
"polluting": False,
"json": None,
}
4 changes: 4 additions & 0 deletions tests/test_parse_qsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ def test_parses_non_ascii_text() -> None:
assert parse_query_string("arabic_text=اختبار اللغة العربية".encode(), "&") == [
("arabic_text", "اختبار اللغة العربية")
]


def test_kwargs() -> None:
assert parse_query_string(qs=b"foo=bar", separator="&") == [("foo", "bar")]
Loading