class BaseEntry(BindableMixIn, ModifiableMixIn):
Known subclasses: pyzim.entry.ContentEntry, pyzim.entry.RedirectEntry
Constructor: BaseEntry(mimetype_id, namespace, revision, url, ...)
Baseclass for entries in a ZIM file.
An entry stores informations about an article/file in the ZIM file.
| Class Method | from |
Read an entry from a file. |
| Method | __init__ |
The default constructor. |
| Method | after |
This method should be called after this object has been read and/or flushed to disk. In other words, it should be called at least once whenever this object matches the state of the object on the disk. |
| Method | flush |
Write this entry to the archive if it is dirty. |
| Method | full |
The full URL, composed of namespace and url. |
| Method | get |
Calculate the size of this object when written to a file. |
| Method | is |
Whether this entry is an article or not. |
| Method | mimetype |
The mimetype as a string. Only available when bound. |
| Method | mimetype |
The index of the mimetype in the mimetypelist. |
| Method | namespace |
The namespace this entry is part of. |
| Method | parameters |
The extra parameters of this entry. |
| Method | remove |
Remove this entry from the archive it is bound to. |
| Method | resolve |
If this entry is a redirect, follow this redirect and any subsequent redirects until a non-redirect is reached and return it. Otherwise, return this entry. |
| Method | revision |
The revision of the content of this entry. Unused, must be 0.. |
| Method | title |
The title of this entry. |
| Method | to |
Serialize this entry into a bytestring and return it. |
| Method | url |
The URL of this entry. |
| Constant | FORMAT |
the struct format to parse the mimetype |
| Constant | LENGTH |
length of the mimetype part of the struct |
| Constant | MIMETYPE |
mimetype index that identifies redirects |
| Instance Variable | mimetype |
The index of the mimetype in the mimetypelist. |
| Instance Variable | namespace |
The namespace this entry is part of. |
| Instance Variable | url |
The URL of this entry. |
| Property | full |
The full URL, composed of namespace and url. |
| Property | is |
Whether this entry is an article or not. |
| Property | is |
True if this entry is a redirect, False otherwise. |
| Property | mimetype |
The mimetype as string. Only available when bound. |
| Property | parameters |
The extra parameters of this entry. |
| Property | revision |
The revision of the content of this entry. Unused, must be 0. |
| Property | title |
The title of this entry. |
| Property | unmodified |
The full URL of this entry of the time this entry was last read or flushed. |
| Method | _get |
Return the size of the mimetype on disk in bytes. |
| Instance Variable | _force |
force-set the article state of this entry |
| Instance Variable | _mimetype |
index of mimetype in the mimetypelist. |
| Instance Variable | _namespace |
namespace this entry is part of |
| Instance Variable | _old |
full URL of entry as of last read/flush |
| Instance Variable | _parameters |
extra parameters. Unused, must be None. |
| Instance Variable | _revision |
the revision of the content of this entry. Unused, must be 0. |
| Instance Variable | _title |
title of this entry |
| Instance Variable | _url |
url of this entry |
Inherited from BindableMixIn:
| Method | bind |
Bind this object to a ZIM file. |
| Method | unbind |
Unbind this object. Can be called multiple times. |
| Property | bound |
Whether this object is bound to a ZIM file or not. |
| Property | zim |
The bound ZIM archive, if any is bound. Otherwise None. |
| Instance Variable | _zim |
the bound ZIM archive or None |
Inherited from ModifiableMixIn (via BindableMixIn):
| Method | add |
Add another modifiable object as a child of this one. |
| Method | dirty |
Setter for ModifiableMixIn.dirty |
| Method | ensure |
If this object is non-mutable, raise an Exception. |
| Method | get |
Return the size of this object on disk as it has been read. |
| Method | get |
Return the size of this object when written to a file before any modifications has been made since the last read/flush. |
| Method | mark |
Convenience function to mark this object as dirty. |
| Method | remove |
Remove a submodifiable from this object. |
| Instance Variable | dirty |
True if this object or a sub-modifiable has been modified. |
| Instance Variable | mutable |
if not nonzero, prevent modifications of this object. |
| Instance Variable | _dirty |
a boolean flag that's nonzero if this object has been modified |
| Instance Variable | _old |
the size of this object on disk before any modifications since the last flush/read |
| Instance Variable | _submodifiables |
a list of child objects, whose dirty state will affect this objects dirty state. |
pyzim.entry.ContentEntry, pyzim.entry.RedirectEntryRead an entry from a file.
| Parameters | |
| f:file-like | file-like object to read from |
seek:int or None | if specified, seek this position of the file before reading |
| Returns | |
pyzim.entry.BaseEntry (or subclass thereof) | the entry in the correct subclass |
pyzim.bindable.BindableMixIn.__init__pyzim.entry.ContentEntry, pyzim.entry.RedirectEntryThe default constructor.
| Parameters | |
mimetypeint | index of mimetype in the mimetypelist. |
namespace:str | namespace this entry is part of |
revision:int | the revision of the content of this entry. Unused, must be 0. |
url:str | url of this entry |
title:str or None | title of this entry |
parameters:list | extra parameters. Unused, must be empty. |
This method should be called after this object has been read and/or flushed to disk. In other words, it should be called at least once whenever this object matches the state of the object on the disk.
This method sets the old disk size, which allows us to late free the allocated space of the old object on disk. Thus, this method requires ModifiableMixIn.get_disk_size to work.
In addition, the object will be marked as non-dirty afterwards.
Write this entry to the archive if it is dirty.
| Raises | |
pyzim.exceptions.NonMutable | if this entry is set to be immutable |
pyzim.exceptions.BindRequired | when not bound |
The full URL, composed of namespace and url.
| Parameters | |
value:str or bytes | value to set |
| Raises | |
TypeError | on invalid type |
ValueError | on invalid value (e.g. empty) @raises pyzim.exceptions.NonMutable: if this entry is set to be immutable. |
pyzim.entry.ContentEntry, pyzim.entry.RedirectEntryCalculate the size of this object when written to a file.
NOTE: in this context, size refers to the direct size of the object. If this object contains references to other objects, their sizes will not be included. For example, a pyzim.entry.ContentEntry also links to a blob, but this function will only return the size of the entry itself, excluding the referenced blob.
| Returns | |
int | the size, in bytes |
Whether this entry is an article or not.
| Parameters | |
value:bool | value to set |
| Raises | |
TypeError | on invalid type |
ValueError | if value is incompatible with namespace |
pyzim.exceptions.NonMutable | if this entry is set to be immutable |
The mimetype as a string. Only available when bound.
| Parameters | |
value:str or bytes | value to set |
| Raises | |
TypeError | on invalid type |
ValueError | if value is invalid (e.g. empty) |
pyzim.exceptions.NonMutable | if this entry is set to be immutable |
pyzim.exceptions.BindRequired | when not bound |
The index of the mimetype in the mimetypelist.
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
ValueError | if the value is invalid (e.g. negative) |
The namespace this entry is part of.
If the namespace is not "C", BaseEntry.is_article will be set to False.
| Parameters | |
value:str or bytes | value to set |
| Raises | |
TypeError | if value is not a string or bytes. |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
ValueError | if the value is invalid (e.g. length != 1) |
The extra parameters of this entry.
| Parameters | |
value:list | value to set |
| Raises | |
TypeError | if value is not the expected type. |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
ValueError | if the value is invalid. |
Remove this entry from the archive it is bound to.
| Parameters | |
blob:str | passed to pyzim.archive.Zim.remove_entry_by_full_url |
| Raises | |
TypeError | on invalid type |
ValueError | on invalid value |
pyzim.exceptions.BindRequired | when not bound |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
pyzim.entry.RedirectEntryIf this entry is a redirect, follow this redirect and any subsequent redirects until a non-redirect is reached and return it. Otherwise, return this entry.
This requires this entry to be bound.
| Returns | |
pyzim.entry.BaseEntry | the first non-redirect entry |
| Raises | |
pyzim.exceptions.BindRequired | if not bound |
The revision of the content of this entry. Unused, must be 0..
| Parameters | |
value:int | value to set |
| Raises | |
TypeError | if value is not an integer |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
ValueError | if the value is invalid (currently, != 0 due to not being implemented by the standard) |
The title of this entry.
| Parameters | |
value:str or bytes or None | value to set |
| Raises | |
TypeError | if value is not a string nor bytes nor None. |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
ValueError | if the value is invalid (e.g. contains null bytes) |
pyzim.entry.ContentEntry, pyzim.entry.RedirectEntrySerialize this entry into a bytestring and return it.
| Returns | |
bytes | a bytestring representing the content of this entry. |
The URL of this entry.
| Parameters | |
value:str or bytes | value to set |
| Raises | |
TypeError | if value is not a string nor bytes. |
pyzim.exceptions.NonMutable | if this entry is set to be inmutable. |
ValueError | if the value is invalid (e.g. contains null bytes) |
Return the size of the mimetype on disk in bytes.
This is a helper method that may be called by subclasses to help their implementation of BaseEntry.get_disk_size-
| Returns | |
int | the size of the mimetype on disk, in bytes |