Esempio n. 1
0
    def from_wsgi(cls,
                  wsgi_input: BytesIO,
                  encoding: str = "utf8") -> "FormBody":
        wsgi_input.seek(0)
        decoded_input = wsgi_input.read().decode(encoding)
        fields = parse_qs(decoded_input)
        instance = cls()

        for name, value in fields.items():
            instance[name] = value

        return instance
Esempio n. 2
0
def test_query_string_with_repeated_key_and_dict():
    result = parse_qs("test_1=1&test_1[a]=2&test_1[b]=3")
    assert result == {"test_1": {"": "1", "a": "2", "b": "3"}}
Esempio n. 3
0
def test_parse_qs_with_broken_key():
    result = parse_qs("test_1[[a][b]]=1&test_1[b]=2&test_1[c]=3")
    assert result == {"test_1[[a][b]]": "1", "test_1": {"b": "2", "c": "3"}}
Esempio n. 4
0
def test_query_string_with_repeated_key_and_arrays():
    result = parse_qs("test_1=1&test_1[]=2&test_1[]=3")
    assert result == {"test_1": ["1", "2", "3"]}
Esempio n. 5
0
def test_parse_qs_with_nested_arrays():
    result = parse_qs("test_1[][]=1&test_1[][]=2&test_1[][]=3")
    assert result == {"test_1": [["1"], ["2"], ["3"]]}
Esempio n. 6
0
def test_parse_qs_with_indexed_arrays():
    result = parse_qs("test_1[0][]=1&test_1[0][]=2&test_1[0][]=3")
    assert result == {"test_1": {"0": ["1", "2", "3"]}}
Esempio n. 7
0
def test_parse_qs_with_dict_values():
    result = parse_qs("test_1[a]=1&test_1[b]=2&test_1[c]=3")
    assert result == {"test_1": {"a": "1", "b": "2", "c": "3"}}
Esempio n. 8
0
def test_parse_qs_with_array_values():
    result = parse_qs("test_1[]=1&test_1[]=2&test_1[]=3")
    assert result == {"test_1": ["1", "2", "3"]}
Esempio n. 9
0
def test_parse_qs_with_multiple_values():
    result = parse_qs("test_1=1&test_2=2&test_3=3")
    assert result == {"test_1": "1", "test_2": "2", "test_3": "3"}
Esempio n. 10
0
def test_parse_qs_with_single_value():
    result = parse_qs("simple_example=test_value")
    assert "simple_example" in result
    assert result["simple_example"] == "test_value"
Esempio n. 11
0
def test_parse_qs_with_no_value():
    result = parse_qs("")
    assert isinstance(result, dict)
    assert result == {}