| 1 | From afd7f482281364a950f220c3d8b44c523fde455d Mon Sep 17 00:00:00 2001
|
| 2 | From: Emmanuel Arias <[email protected]>
|
| 3 | Date: Wed, 3 Jun 2026 09:22:02 -0300
|
| 4 | Subject: [PATCH] Fix FormParser call
|
| 5 |
|
| 6 | Replace FileClass arg with an method callback, matching the new
|
| 7 | FormParser API.
|
| 8 |
|
| 9 | Closes: #38
|
| 10 | ---
|
| 11 | asgi_csrf.py | 11 +++--------
|
| 12 | 1 file changed, 3 insertions(+), 8 deletions(-)
|
| 13 |
|
| 14 | diff --git a/asgi_csrf.py b/asgi_csrf.py
|
| 15 | index f744ad9..e89225c 100644
|
| 16 | |
| 17 | |
| 18 | @@ -271,12 +271,8 @@ def on_field(field):
|
| 19 | csrftoken = field.value.decode("utf-8")
|
| 20 | raise TokenFound(csrftoken)
|
| 21 |
|
| 22 | - class ErrorOnWrite:
|
| 23 | - def __init__(self, file_name, field_name, config):
|
| 24 | - pass
|
| 25 | -
|
| 26 | - def write(self, data):
|
| 27 | - raise FileBeforeToken
|
| 28 | + def on_file(file):
|
| 29 | + raise FileBeforeToken()
|
| 30 |
|
| 31 | body = b""
|
| 32 | more_body = True
|
| 33 | @@ -291,9 +287,8 @@ async def replay_receive():
|
| 34 | form_parser = FormParser(
|
| 35 | "multipart/form-data",
|
| 36 | on_field,
|
| 37 | - lambda: None,
|
| 38 | + on_file,
|
| 39 | boundary=boundary,
|
| 40 | - FileClass=ErrorOnWrite,
|
| 41 | )
|
| 42 | try:
|
| 43 | while more_body:
|