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