Pyjo.Content.Single - HTTP content¶
import Pyjo.Content.Single
single = Pyjo.Content.Single.new()
single.parse(b"Content-Length: 12\x0d\x0a\x0d\x0aHello World!")
print(single.headers.content_length)
Pyjo.Content.Single
is a container for HTTP content based on
RFC 7230 and
RFC 7231.
Events¶
Pyjo.Content.Single
inherits all events from Pyjo.Content
and can
emit the following new ones.
upgrade¶
@single.on
def upgrade(single, multi):
...
Emitted when content gets upgraded to a Pyjo.Content.MultiPart
object.
from Pyjo.Regexp import r
@single.on
def upgrade(single, multi):
m = r(r'multipart\/([^;]+)', 'i').search(multi.headers.content_type)
if m:
print("Multipart: {0}".format(m.group(1)))
Classes¶
-
Pyjo_Content_Single.
__init__
(**kwargs)¶ single = Pyjo.Content.Single.new() single = Pyjo.Content.Single.new(asset=Pyjo.Asset.File.new())
Construct a new
Pyjo.Content.Single
object and subscribe toread
event with default content parser.
-
class
Pyjo.Content.Single.
Pyjo_Content_Single
(**kwargs)¶ Pyjo.Content.Single
inherits all attributes and methods fromPyjo.Content
and implements the following new ones.-
__init__
(**kwargs) single = Pyjo.Content.Single.new() single = Pyjo.Content.Single.new(asset=Pyjo.Asset.File.new())
Construct a new
Pyjo.Content.Single
object and subscribe toread
event with default content parser.
-
asset
= None¶ asset = single.asset single.asset = Pyjo.Asset.Memory.new()
The actual content, defaults to a
Pyjo.Asset.Memory
object withPyjo.Asset.Memory.auto_upgrade
enabled.
-
auto_upgrade
= None¶ boolean = single.auto_upgrade single.auto_upgrade = boolean
Try to detect multipart content and automatically upgrade to a
Pyjo.Content.MultiPart
object, defaults to a true value.
-
body_contains
(chunk)¶ boolean = single.body_contains(b'1234567')
Check if content contains a specific string.
-
body_size
¶ size = single.body_size
Content size in bytes.
-
clone
()¶ clone = single.clone()
Clone content if possible, otherwise return
None
.
-
get_body_chunk
(offset)¶ bstring = single.get_body_chunk(0)
Get a chunk of content starting from a specific position.
-
parse
(chunk)¶ single = single.parse(b"Content-Length: 12\x0d\x0a\x0d\x0aHello World!") multi = single.parse(b"Content-Type: multipart/form-data\x0d\x0a\x0d\x0a")
Parse content chunk and upgrade to
Pyjo.Content.MultiPart
object if necessary.
-
-
Pyjo.Content.Single.
object
¶ alias of
Pyjo_Content_Single