(fields: dict[str, str], file_field: str, file_path: Path)
| 106 | |
| 107 | |
| 108 | def _multipart_form(fields: dict[str, str], file_field: str, file_path: Path) -> tuple[bytes, str]: |
| 109 | boundary = f"----modly-cli-{time.time_ns()}" |
| 110 | parts: list[bytes] = [] |
| 111 | |
| 112 | for name, value in fields.items(): |
| 113 | parts.extend([ |
| 114 | f"--{boundary}\r\n".encode(), |
| 115 | f'Content-Disposition: form-data; name="{name}"\r\n\r\n'.encode(), |
| 116 | str(value).encode("utf-8"), |
| 117 | b"\r\n", |
| 118 | ]) |
| 119 | |
| 120 | content_type = mimetypes.guess_type(file_path.name)[0] or "application/octet-stream" |
| 121 | parts.extend([ |
| 122 | f"--{boundary}\r\n".encode(), |
| 123 | f'Content-Disposition: form-data; name="{file_field}"; filename="{file_path.name}"\r\n'.encode(), |
| 124 | f"Content-Type: {content_type}\r\n\r\n".encode(), |
| 125 | file_path.read_bytes(), |
| 126 | b"\r\n", |
| 127 | f"--{boundary}--\r\n".encode(), |
| 128 | ]) |
| 129 | return b"".join(parts), f"multipart/form-data; boundary={boundary}" |
| 130 | |
| 131 | |
| 132 | def _workspace_relative_path(output_url: str) -> str: |
no outgoing calls
no test coverage detected