class documentation

An entry for a redirect.

Class Method from_file Read a content entry from a file.
Method __init__ The default constructor.
Method follow Follow this redirect and the next entry.
Method get_disk_size Calculate the size of this object when written to a file.
Method redirect_index.setter The position/offset of the entry in the URL entry list this entry redirects to.
Method resolve Follow this redirect and any subsequent redirects until a non-redirect is reached.
Method to_bytes Serialize this entry into a bytestring and return it.
Constant FORMAT_NMT the format of this entry, excluding the mimetype
Constant LENGTH_NMT Undocumented
Class Variable LENGTH_FMT length of this entry, excluding mimetype and zero terminated parts
Property redirect_index The position/offset of the entry in the URL entry list this entry redirects to.
Instance Variable _redirect_index position/offset of the entry in the URL entry list this entry redirects to

Inherited from BaseEntry:

Method after_flush_or_read 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_url.setter The full URL, composed of namespace and url.
Method is_article.setter Whether this entry is an article or not.
Method mimetype.setter The mimetype as a string. Only available when bound.
Method mimetype_id.setter The index of the mimetype in the mimetypelist.
Method namespace.setter The namespace this entry is part of.
Method parameters.setter The extra parameters of this entry.
Method remove Remove this entry from the archive it is bound to.
Method revision.setter The revision of the content of this entry. Unused, must be 0..
Method title.setter The title of this entry.
Method url.setter The URL of this entry.
Constant FORMAT_MT the struct format to parse the mimetype
Constant LENGTH_MT length of the mimetype part of the struct
Constant MIMETYPE_ID_REDIRECT mimetype index that identifies redirects
Instance Variable mimetype_id 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_url The full URL, composed of namespace and url.
Property is_article Whether this entry is an article or not.
Property is_redirect 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_full_url The full URL of this entry of the time this entry was last read or flushed.
Method _get_mimetype_size Return the size of the mimetype on disk in bytes.
Instance Variable _force_is_article force-set the article state of this entry
Instance Variable _mimetype_id index of mimetype in the mimetypelist.
Instance Variable _namespace namespace this entry is part of
Instance Variable _old_full_url 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 (via BaseEntry):

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 BaseEntry, BindableMixIn):

Method add_submodifiable Add another modifiable object as a child of this one.
Method dirty.setter Setter for ModifiableMixIn.dirty
Method ensure_mutable If this object is non-mutable, raise an Exception.
Method get_initial_disk_size Return the size of this object on disk as it has been read.
Method get_unmodified_disk_size Return the size of this object when written to a file before any modifications has been made since the last read/flush.
Method mark_dirty Convenience function to mark this object as dirty.
Method remove_submodifiable 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_disk_size 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.
def from_file(cls, f, mimetype=None, seek=None):

Read a content entry from a file.

Parameters
f:file-likefile-like object to read from
mimetype:intindex of mimetype. If specified, do not read it from file
seek:int or Noneif specified, seek this position of the file before reading
Returns
pyzim.entry.RedirectEntrythe entry read from the file
def __init__(self, namespace, revision, redirect_index, url, title, parameters):

The default constructor.

Parameters
namespace:strnamespace this entry is part of
revision:intthe revision of the content of this entry. Unused, must be 0.
redirect_index:intposition/offset of the entry this entry redirects to
url:strurl of this entry
title:strtitle of this entry
parameters:listextra parameters. Unused, must be empty.
def follow(self):

Follow this redirect and the next entry.

This requires this entry to be bound. The next entry may be a redirect too.

Returns
pyzim.entry.BaseEntrythe next entry
Raises
pyzim.exceptions.BindRequiredif not bound
def get_disk_size(self):

Calculate 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
intthe size, in bytes
def redirect_index(self, value):

The position/offset of the entry in the URL entry list this entry redirects to.

Parameters
value:intvalue to set
Raises
TypeErrorif value is not an integer
pyzim.exceptions.NonMutableif this entry is set to be inmutable.
ValueErrorif the value is invalid (e.g. negative)
def resolve(self):

Follow this redirect and any subsequent redirects until a non-redirect is reached.

This requires this entry to be bound.

Returns
pyzim.entry.BaseEntrythe first non-redirect entry
Raises
pyzim.exceptions.BindRequiredif not bound
def to_bytes(self):

Serialize this entry into a bytestring and return it.

Returns
bytesa bytestring representing the content of this entry.
FORMAT_NMT: str =

the format of this entry, excluding the mimetype

Value
constants.ENDIAN + 'BcII'
LENGTH_NMT =

Undocumented

Value
struct.calcsize(FORMAT_NMT)
LENGTH_FMT: int =

length of this entry, excluding mimetype and zero terminated parts

redirect_index: int =

The position/offset of the entry in the URL entry list this entry redirects to.

_redirect_index: int =

position/offset of the entry in the URL entry list this entry redirects to