This commit is contained in:
Sky O 2024-03-29 16:50:18 +00:00
parent dd381ba452
commit e43e0ed5d5

View File

@ -6,10 +6,16 @@ class Part:
headers = [] headers = []
data : bytes data : bytes
def __repr__(self):
return f"Part(headers={repr(self.headers)}, data={self.data})"
class Header: class Header:
name : bytes name : bytes
value : bytes value : bytes
def __repr__(self):
return f"{self.name}:{self.value}"
def get_body_from_form_data( def get_body_from_form_data(
body: bytes, boundary: str body: bytes, boundary: str
) -> Tuple[Optional[bytes], Dict[str, str]]: ) -> Tuple[Optional[bytes], Dict[str, str]]:
@ -80,16 +86,21 @@ def get_body_from_form_data(
print("YO PARTS", parts) print("YO PARTS", parts)
data = None data = None
headers: Dict[str, str] = {} headers: Dict[str, str] = {}
for prt in parser.parts():
if prt.name == "upload_file": # for part in parts:
headers["key"] = prt.name # for header in part.headers:
data = prt.file.read() # if header.key
else:
val = prt.file.read() # for prt in parser.parts():
if prt.name == "file": # if prt.name == "upload_file":
data = val # headers["key"] = prt.name
else: # data = prt.file.read()
headers[prt.name] = val.decode("utf-8") # else:
# val = prt.file.read()
# if prt.name == "file":
# data = val
# else:
# headers[prt.name] = val.decode("utf-8")
return data, headers return data, headers
# form_data file # form_data file