Pyjo.Content.MultiPart - HTTP multipart content¶
import Pyjo.Content.MultiPart
multi = Pyjo.Content.MultiPart.new()
multi.parse(b'Content-Type: multipart/mixed; boundary=---foobar')
single = multi.parts[4]
print(single.headers.content_length)
Pyjo.Content.MultiPart
is a container for HTTP multipart content based on
RFC 7230,
RFC 7231 and
RFC 2388.
Events¶
Pyjo.Content.MultiPart
inherits all events from Pyjo.Content
and can
emit the following new ones.
part¶
@multi.on
def part(multi, single):
...
Emitted when a new Pyjo.Content.Single
part starts.
from Pyjo.Regexp import r
@multi.on
def part(multi, single):
m = r('name="([^"]+)"').search(single.headers.content_disposition)
if m:
print("Fields: {0}".format(m.group(1)))
Classes¶
-
Pyjo_Content_MultiPart.
__init__
(**kwargs)¶ multi = Pyjo.Content.MultiPart.new() multi = Pyjo.Content.MultiPart.new(parts=[Pyjo.Content.Single.new()])
Construct a new
Pyjo.Content.MultiPart
object and subscribe toread
event with default content parser.
-
class
Pyjo.Content.MultiPart.
Pyjo_Content_MultiPart
(**kwargs)¶ Pyjo.Content.MultiPart
inherits all attributes and methods fromPyjo.Content
and implements the following new ones.-
__init__
(**kwargs) multi = Pyjo.Content.MultiPart.new() multi = Pyjo.Content.MultiPart.new(parts=[Pyjo.Content.Single.new()])
Construct a new
Pyjo.Content.MultiPart
object and subscribe toread
event with default content parser.
-
body_contains
(chunk)¶ boolean = multi.body_contains(b'1234567')
Check if content contains a specific string.
-
body_size
¶ size = multi.body_size
Content size in bytes.
-
build_boundary
()¶ boundary = multi.build_boundary()
Generate a suitable boundary for content and add it to
Content-Type
header.
-
clone
()¶ clone = multi.clone()
Clone content if possible, otherwise return
None
.
-
get_body_chunk
(offset)¶ bstring = multi.get_body_chunk(0)
Get a chunk of content starting from a specific position.
-
is_multipart
¶ true = multi.is_multipart
True.
-
parts
= None¶ parts = multi.parts multi.parts = []
Content parts embedded in this multipart content, usually
Pyjo.Content.Single
objects.
-
-
Pyjo.Content.MultiPart.
object
¶ alias of
Pyjo_Content_MultiPart