Pyjo.Asset - HTTP content storage base class¶
from Pyjo.Asset import Asset
class MyAsset(Asset):
def add_chunk(self, chunk): ...
def contains(self, string): ...
def get_chunk(self, offset, max=None): ...
def move_to(self, to): ...
@property
def mtime(self): ...
@property
def size(self): ...
def slurp(self): ...
def to_file(self): ...
# Or import the module, as in Google Python Style Guide
import Pyjo.Asset
class MyAsset(Pyjo.Asset.object):
def add_chunk(self, chunk): ...
def contains(self, string): ...
def get_chunk(self, offset, max=None): ...
def move_to(self, to): ...
@property
def mtime(self): ...
@property
def size(self): ...
def slurp(self): ...
def to_file(self): ...
Pyjo.Asset is an abstract base class for HTTP content storage
backends, like Pyjo.Asset.File and Pyjo.Asset.Memory.
Events¶
Pyjo.Asset inherits all events from Pyjo.EventEmitter.
See also¶
Pyjoyment, https://mojolicious.org.
Ported from Mojo::Asset of Mojolicious 9.49.
- class Pyjo.Asset.Pyjo_Asset(*, end_range: int | None = None, start_range: int = 0)[source]¶
Pyjo.Assetinherits all methods fromPyjo.EventEmitterand implements the following new ones.- add_chunk(chunk: bytes) Pyjo_Asset[source]¶
asset = asset.add_chunk(b'foo bar baz')
Add chunk of data to asset. Meant to be overloaded in a subclass.
- contains(string: bytes) int[source]¶
position = asset.contains(b'bar')
Check if asset contains a specific string. Meant to be overloaded in a subclass.
- end_range¶
end = asset.end_range asset.end_range = 8
Pretend file ends earlier.
- get_chunk(offset: int, max: int | None = None) bytes[source]¶
chunk = asset.get_chunk(offset) chunk = asset.get_chunk(offset, max)
Get chunk of data starting from a specific position, defaults to a maximum chunk size of
131072bytes (128KiB). Meant to be overloaded in a subclass.
- property is_file: bool[source]¶
boolean = asset.is_file
False, this is not a
Pyjo.Asset.Fileobject.
- property is_range: bool[source]¶
boolean = asset.is_range
Check if asset has a
start_rangeorend_range.
- move_to(to: Anything) Self[source]¶
asset = asset.move_to('/home/sri/foo.txt')
Move asset data into a specific file. Meant to be overloaded in a subclass.
- property mtime: float[source]¶
mtime = asset.mtime
Modification time of asset. Meant to be overloaded in a subclass.
- property size: int[source]¶
size = asset.size
Size of asset data in bytes. Meant to be overloaded in a subclass.
- slurp() bytes[source]¶
content = asset.slurp()
Read all asset data at once. Meant to be overloaded in a subclass.
- start_range¶
start = asset.start_range asset.start_range = 3
Pretend file starts later.
- to_file() Pyjo_Asset[source]¶
file = asset.to_file()
Convert asset to
Pyjo.Asset.Fileobject. Meant to be overloaded in a subclass.