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.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:
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:
headers (
Soup.MessageHeaders
) – the headers of the HTTP message to parsebody (
Soup.MessageBody
) – 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
New in version 2.26.
- append_form_file(control_name, filename, content_type, body)¶
- Parameters:
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:
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:
headers (
Soup.MessageHeaders
) – the MIME part headersbody (
Soup.Buffer
) – 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.)
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:
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 todest_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.