From 0b80debad23c282af0f5447b06a6661f2227d99e Mon Sep 17 00:00:00 2001 From: Sky O Date: Fri, 29 Mar 2024 14:06:09 +0000 Subject: [PATCH] Test the parsing --- moto/moto_proxy/utils.py | 52 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/moto/moto_proxy/utils.py b/moto/moto_proxy/utils.py index 9a9669ac5..e1ea42dec 100644 --- a/moto/moto_proxy/utils.py +++ b/moto/moto_proxy/utils.py @@ -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():