Test the parsing

This commit is contained in:
Sky O 2024-03-29 14:06:09 +00:00
parent b7918c2cc5
commit 0b80debad2

View File

@ -6,8 +6,58 @@ import multipart
def get_body_from_form_data(
body: bytes, boundary: str
) -> Tuple[Optional[bytes], Dict[str, str]]:
parser = multipart.MultipartParser(boundary=boundary)
print("YO BYTES", body)
def on_part_begin(string: str):
print("YO PART BEGAN")
return
def on_part_data(b,s,e):
print("YO PART DATA", b, s, e)
return
def on_part_end(string: str):
print("YO PART ENDED")
return
def on_header_begin():
print("YO HEADER BEGIN")
return
def on_header_end():
print("YO HEADER END")
return
def on_header_field(b,s,e):
print("YO HEADER FIELD", b, s, e)
return
def on_header_value(b,s,e):
print("YO HEADER FIELD", b, s, e)
return
def on_headers_finished():
print("YO HEADER FINISHED")
return
def on_end():
print("YO END")
return
parser = multipart.MultipartParser(boundary=boundary,
callbacks={
"on_part_begin": on_part_begin,
"on_part_data": on_part_data,
"on_part_end": on_part_end,
"on_header_field": on_header_field,
"on_header_value": on_header_value,
"on_header_end": on_header_end,
"on_headers_finished": on_headers_finished,
"on_end": on_end,
},
)
parser.write(body)
parser.finalize(body)
data = None
headers: Dict[str, str] = {}
for prt in parser.parts():