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, dest_body)

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.

New in version 2.26.

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/”.

New in version 2.26.

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

New in version 2.26.

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

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

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

  • body (Soup.Buffer) – the file data

Adds a new MIME part containing body to self, using “Content-Disposition: form-data”, as per the HTML forms specification. See Soup.form_request_new_from_multipart() for more details.

New in version 2.26.

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, using “Content-Disposition: form-data”, as per the HTML forms specification. See Soup.form_request_new_from_multipart() for more details.

New in version 2.26.

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.)

New in version 2.26.

free()

Frees self

New in version 2.26.

get_length()
Returns:

the number of body parts in self

Return type:

int

Gets the number of body parts in self

New in version 2.26.

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: Soup.Buffer)

Gets the indicated body part from self.

New in version 2.26.

to_message(dest_headers, dest_body)
Parameters:
  • dest_headers (Soup.MessageHeaders) – the headers of the HTTP message to serialize self to

  • dest_body (Soup.MessageBody) – the body of the HTTP message to serialize self to

Serializes self to dest_headers and dest_body.

New in version 2.26.