in runtime_scripts/replay.py [0:0]
def convert_data_to_dict(self, content, content_type):
"""
Convert data to a dictionary.
Args:
content (bytes): The data to convert.
content_type (str): The content type header value.
Returns:
dict: The converted data.
"""
data = {}
try:
if content_type.startswith("application/json"):
data = json.loads(content)
elif content_type.startswith("multipart/form-data"):
decoded_content = decoder.MultipartDecoder(
content=content, content_type=content_type
)
name_pattern = re.compile(r'name="(.+?)"')
for part in decoded_content.parts:
try:
text = part.text
except UnicodeDecodeError:
# Attachment data is binary, and we don't need to process it
continue
headers = part.headers.get(b"Content-Disposition", b"").decode()
match = name_pattern.search(headers)
if not match:
continue
name = match.group(1)
data[name] = text
elif content_type.startswith("application/x-www-form-urlencoded"):
content_str = content.decode("utf-8")
for pair in content_str.split("&"):
name, value = pair.split("=")
if not name:
continue
data[name] = value
except Exception as e:
logger.warning(f"Failed to convert data: {e}")
return data