Soup.Multipart¶
Fields¶
None
Methods¶
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
andmultipart/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 useSoup.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:
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:
headers (
Soup.MessageHeaders
) – the headers of the HTTP message to parsebody (
GLib.Bytes
) – the body of the HTTP message to parse
- Returns:
a new
Soup.Multipart
(orNone
if the message couldn’t be parsed or wasn’t multipart).- Return type:
Parses headers and body to form a new
Soup.Multipart
- append_form_file(control_name, filename, content_type, body)¶
- Parameters:
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:
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:
headers (
Soup.MessageHeaders
) – the MIME part headersbody (
GLib.Bytes
) – the MIME part body
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:
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.