:right-sidebar: True Multipart =================================================================== .. currentmodule:: gi.repository.Soup .. class:: Multipart(**kwargs) :no-contents-entry: Represents a multipart HTTP message body, parsed according to the syntax of RFC 2046. Of particular interest to HTTP are ``multipart/byte-ranges`` and ``multipart/form-data``\, Although the headers of a :obj:`~gi.repository.Soup.Multipart` body part will contain the full headers from that body part, libsoup does not interpret them according to MIME rules. For example, each body part is assumed to have "binary" Content-Transfer-Encoding, even if its headers explicitly state otherwise. In other words, don't try to use :obj:`~gi.repository.Soup.Multipart` for handling real MIME multiparts. Constructors ------------ .. rst-class:: interim-class .. class:: Multipart :no-index: .. classmethod:: new(mime_type: str) -> ~gi.repository.Soup.Multipart Creates a new empty :obj:`~gi.repository.Soup.Multipart` with a randomly-generated boundary string. Note that ``mime_type`` must be the full MIME type, including "multipart/". See also: :obj:`~gi.repository.Message.new_from_multipart`\. :param mime_type: the MIME type of the multipart to create. .. classmethod:: new_from_message(headers: ~gi.repository.Soup.MessageHeaders, body: ~gi.repository.GLib.Bytes) -> ~gi.repository.Soup.Multipart | None Parses ``headers`` and ``body`` to form a new :obj:`~gi.repository.Soup.Multipart` :param headers: the headers of the HTTP message to parse :param body: the body of the HTTP message to parse Methods ------- .. rst-class:: interim-class .. class:: Multipart :no-index: .. method:: append_form_file(control_name: str, filename: str | None, content_type: str | None, body: ~gi.repository.GLib.Bytes) -> None Adds a new MIME part containing ``body`` to ``multipart`` Uses "Content-Disposition: form-data", as per the HTML forms specification. :param control_name: the name of the control associated with this file :param filename: the name of the file, or :const:`None` if not known :param content_type: the MIME type of the file, or :const:`None` if not known :param body: the file data .. method:: append_form_string(control_name: str, data: str) -> None Adds a new MIME part containing ``data`` to ``multipart``\. Uses "Content-Disposition: form-data", as per the HTML forms specification. :param control_name: the name of the control associated with ``data`` :param data: the body data .. method:: append_part(headers: ~gi.repository.Soup.MessageHeaders, body: ~gi.repository.GLib.Bytes) -> None Adds a new MIME part to ``multipart`` with the given headers and body. (The multipart will make its own copies of ``headers`` and ``body``\, so you should free your copies if you are not using them for anything else.) :param headers: the MIME part headers :param body: the MIME part body .. method:: free() -> None Frees ``multipart``\. .. method:: get_length() -> int Gets the number of body parts in ``multipart``\. .. method:: get_part(part: int) -> ~typing.Tuple[bool, ~gi.repository.Soup.MessageHeaders, ~gi.repository.GLib.Bytes] Gets the indicated body part from ``multipart``\. :param part: the part number to get (counting from 0) .. method:: to_message(dest_headers: ~gi.repository.Soup.MessageHeaders) -> ~gi.repository.GLib.Bytes Serializes ``multipart`` to ``dest_headers`` and ``dest_body``\. :param dest_headers: the headers of the HTTP message to serialize ``multipart`` to