Hi,
asgi-csrf is not compatible with the new python-multipart
38s E TypeError: FormParser.__init__() got an unexpected keyword argument 'FileClass'
https://github.com/simonw/asgi-csrf/issues/38
Greetings
Alexandre
38s tests/test_asgi_csrf.py::test_multipart FAILED [ 27%]
38s
38s =================================== FAILURES ===================================
38s ________________________________ test_multipart ________________________________
38s
38s csrftoken = 'InRva2VuIg.49BUIh1HVBjcyCpg_4018iFDFdY'
38s
38s @pytest.mark.asyncio
38s async def test_multipart(csrftoken):
38s async with httpx.AsyncClient(
38s transport=httpx.ASGITransport(
38s app=asgi_csrf(hello_world_app, signing_secret=SECRET)
38s ),
38s cookies={"csrftoken": csrftoken},
38s ) as client:
38s > response = await client.post(
38s "http://localhost/",
38s data={"csrftoken": csrftoken},
38s files={"csv": ("data.csv", "blah,foo\n1,2", "text/csv")},
38s )
38s
38s tests/test_asgi_csrf.py:238:
38s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
38s /usr/lib/python3/dist-packages/httpx/_client.py:1859: in post
38s return await self.request(
38s /usr/lib/python3/dist-packages/httpx/_client.py:1540: in request
38s return await self.send(request, auth=auth, follow_redirects=follow_redirects)
38s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38s /usr/lib/python3/dist-packages/httpx/_client.py:1629: in send
38s response = await self._send_handling_auth(
38s /usr/lib/python3/dist-packages/httpx/_client.py:1657: in _send_handling_auth
38s response = await self._send_handling_redirects(
38s /usr/lib/python3/dist-packages/httpx/_client.py:1694: in _send_handling_redirects
38s response = await self._send_single_request(request)
38s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38s /usr/lib/python3/dist-packages/httpx/_client.py:1730: in _send_single_request
38s response = await transport.handle_async_request(request)
38s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38s /usr/lib/python3/dist-packages/httpx/_transports/asgi.py:170: in handle_async_request
38s await self.app(scope, receive, send)
38s /usr/lib/python3/dist-packages/asgi_csrf.py:198: in app_wrapped_with_csrf
38s ) = await _parse_multipart_form_data(boundary, receive)
38s ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
38s
38s boundary = b'd1ebe15d38a194610e63bb805c28d70d'
38s receive = <function ASGITransport.handle_async_request.<locals>.receive at 0x7faa72786da0>
38s
38s async def _parse_multipart_form_data(boundary, receive):
38s # Returns (csrftoken, replay_receive) - or raises an exception
38s csrftoken = None
38s
38s def on_field(field):
38s if field.field_name == b"csrftoken":
38s csrftoken = field.value.decode("utf-8")
38s raise TokenFound(csrftoken)
38s
38s class ErrorOnWrite:
38s def __init__(self, file_name, field_name, config):
38s pass
38s
38s def write(self, data):
38s raise FileBeforeToken
38s
38s body = b""
38s more_body = True
38s messages = []
38s
38s async def replay_receive():
38s if messages:
38s return messages.pop(0)
38s else:
38s return await receive()
38s
38s > form_parser = FormParser(
38s "multipart/form-data",
38s on_field,
38s lambda: None,
38s boundary=boundary,
38s FileClass=ErrorOnWrite,
38s )
38s E TypeError: FormParser.__init__() got an unexpected keyword argument 'FileClass'
38s