示例#1
0
def test_parse_header_str_without_encoding():
    name, filename, mimetype, content_length = File.parse(
        b'\r\nContent-Disposition: form-data; name="test_file"; '
        b'filename="conftest.py"; filename*=utf-8\'\'conftest.py'
        b'\r\nContent-Type: text/x-python\r\nContent-Length: 0')
    assert filename == "conftest.py"
    assert name == "test_file"
    assert mimetype == "text/x-python"
    assert content_length == 0
示例#2
0
def test_parse_header_str_without_content_length_and_content_type():
    name, filename, mimetype, content_length = File.parse(
        b'\r\nContent-Disposition: form-data; name="test_file"; '
        b'filename*=utf-8\'\'%E6%BB%8B%E5%85%BB%E7%BB%86%E8%83%9E%E8%82%BF%E7%98%A4.pdf'
    )
    assert filename == "滋养细胞肿瘤.pdf"
    assert name == "test_file"
    assert mimetype is None
    assert content_length == 0
示例#3
0
def test_parse_header_str_with_encoding():
    name, filename, mimetype, content_length = File.parse(
        b'\r\nContent-Disposition: form-data; name="test_file"; '
        b'filename="%E6%BB%8B%E5%85%BB%E7%BB%86%E8%83%9E%E8%82%BF%E7%98%A4.pdf"; '
        b'filename*=utf-8\'\'%E6%BB%8B%E5%85%BB%E7%BB%86%E8%83%9E%E8%82%BF%E7%98%A4.pdf'
        b'\r\nContent-Type: application/pdf\r\nContent-Length: 1292384')
    assert filename == "滋养细胞肿瘤.pdf"
    assert name == "test_file"
    assert mimetype == "application/pdf"
    assert content_length == 1292384
示例#4
0
def test_parse_header_str_without_content_length_and_content_type_with_encoding(
):
    name, filename, mimetype, content_length = File.parse(
        b"\r\nContent-Disposition: form-data; "
        b"name*=utf-8''%E6%BB%8B%E5%85%BB%E7%BB%86%E8%83%9E%E8%82%BF%E7%98%A4.pdf; "
        b"filename*=utf-8''%E6%BB%8B%E5%85%BB%E7%BB%86%E8%83%9E%E8%82%BF%E7%98%A4.pdf"
    )
    assert filename == "滋养细胞肿瘤.pdf"
    assert name == "滋养细胞肿瘤.pdf"
    assert mimetype is None
    assert content_length == 0