Soup.Multipart

Fields

None

Methods

class

new (mime_type)

class

new_from_message (headers, body)

append_form_file (control_name, filename, content_type, body)

append_form_string (control_name, data)

append_part (headers, body)

free ()

get_length ()

get_part (part)

to_message (dest_headers)

Details

class Soup.Multipart

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 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 Soup.Multipart for handling real MIME multiparts.

classmethod new(mime_type)
Parameters:

mime_type (str) – the MIME type of the multipart to create.

Returns:

a new empty Soup.Multipart of the given mime_type

Return type:

Soup.Multipart

Creates a new empty Soup.Multipart with a randomly-generated boundary string.

Note that mime_type must be the full MIME type, including “multipart/”.

See also: [ctor`Message`.new_from_multipart].

classmethod new_from_message(headers, body)
Parameters:
Returns:

a new Soup.Multipart (or None if the message couldn’t be parsed or wasn’t multipart).

Return type:

Soup.Multipart or None

Parses headers and body to form a new Soup.Multipart

append_form_file(control_name, filename, content_type, body)
Parameters:
  • control_name (str) – the name of the control associated with this file

  • filename (str or None) – the name of the file, or None if not known

  • content_type (str or None) – the MIME type of the file, or None if not known

  • body (GLib.Bytes) – the file data

Adds a new MIME part containing body to self

Uses “Content-Disposition: form-data”, as per the HTML forms specification.

append_form_string(control_name, data)
Parameters:
  • control_name (str) – the name of the control associated with data

  • data (str) – the body data

Adds a new MIME part containing data to self.

Uses “Content-Disposition: form-data”, as per the HTML forms specification.

append_part(headers, body)
Parameters:

Adds a new MIME part to self 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.)

free()

Frees self.

get_length()
Returns:

the number of body parts in self

Return type:

int

Gets the number of body parts in self.

get_part(part)
Parameters:

part (int) – the part number to get (counting from 0)

Returns:

True on success, False if part is out of range (in which case headers and body won’t be set)

headers:

return location for the MIME part headers

body:

return location for the MIME part body

Return type:

(bool, headers: Soup.MessageHeaders, body: GLib.Bytes)

Gets the indicated body part from self.

to_message(dest_headers)
Parameters:

dest_headers (Soup.MessageHeaders) – the headers of the HTTP message to serialize self to

Returns:

the body of the HTTP message to serialize self to

Return type:

dest_body: GLib.Bytes

Serializes self to dest_headers and dest_body.