class documentation

The counter keeps track of how many entries of each mimetype there is.

Please note that the counter counts when an entry is written. If you are using the item interface, you may have to flush the archive first.

Class Method from_string Initialize a counter from a string.
Class Method load_from_archive Initialize the counter from an existing archive.
Method __init__ The default constructor.
Method after_content_flush Called during flush, after all content has been flushed.
Method after_entry_remove Called after an entry has been removed.
Method after_entry_write Called after an entry was written.
Method decrement_count Increment the count for the specified mimetype.
Method get_count Get the count of a specific mimetype.
Method get_disk_size Calculate the size of this object when written to a file.
Method increment_count Increment the count for the specified mimetype.
Method on_install Called when this processor is installed to a ZIM file.
Method to_string Dump the values of this counter into a string.
Instance Variable counts a dict mapping mimetype to number of occurences
Instance Variable zim Undocumented
Method _should_count_entry Return True if the entry should be counted.

Inherited from ModifiableMixIn:

Method add_submodifiable Add another modifiable object as a child of this one.
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 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.

Inherited from BaseProcessor (via ModifiableMixIn):

Method after_close Called when the archive has been closed.
Method after_cluster_get Called when pyzim.archive.Zim.get_cluster_at was called.
Method after_cluster_write Called after a cluster has been written.
Method after_entry_get Called when pyzim.archive.Zim.get_entry_at was called, before the entry is returned.
Method after_flush Called after the archive has been flushed.
Method before_close Called when the archive will be closed.
Method before_cluster_get Called when pyzim.archive.Zim.get_cluster_at was called.
Method before_cluster_write Called before a cluster will be written.
Method before_entry_get Called when pyzim.archive.Zim.get_entry_at was called.
Method before_entry_remove Called before an entry will be removed.
Method before_entry_write Called before an entry will be written.
Method before_flush Called before the archive will be flushed.
Method on_add_redirect Called when a redirect will be added.
def from_string(cls, s):

Initialize a counter from a string.

Parameters
s:str or bytesstring to initialize from
Returns
Counterthe initialized counter
Raises
TypeErroron type error
ValueErroron invalid value
def load_from_archive(cls, zim, how='load_or_reinit'):

Initialize the counter from an existing archive.

The 'how' parameter specifies how the counter should be initialized. Supported values are:

  • "load": load from an archive, returning None if not possible
  • "ignore": do not initialize counter
  • "reinit": create a new counter and count all existing entries in archive
  • "load_or_reinit": attempt to "load", falling back to "reinit", default
Parameters
zim:pyzim.archive.ZimZIM archive to initialize from
how:strhow to initialize the counter
Returns
Counter or Nonea counter reflecting the mimetype count in the archive
Raises
TypeErroron invalid type
ValueErroron invalid value
def __init__(self, counts=None):

The default constructor.

Parameters
counts:None or dict mapping str to intinitial count of each mimetype
def after_content_flush(self, **kwargs):

Called during flush, after all content has been flushed.

At this point, the various pointerlists may not have yet been flushed.

Parameters
**kwargs:dictextra keyword arguments
def after_entry_remove(self, **kwargs):

Called after an entry has been removed.

Keyword arguments:

Parameters
**kwargs:dictextra keyword arguments
def after_entry_write(self, **kwargs):

Called after an entry was written.

Keyword arguments:

Parameters
**kwargs:dictextra keyword arguments
def decrement_count(self, mimetype):

Increment the count for the specified mimetype.

Parameters
mimetype:strmimetype to increase count of
Raises
ValueErrorif current count for mimetype is not at least 1
TypeErroron type error
def get_count(self, mimetype):

Get the count of a specific mimetype.

Parameters
mimetype:strmimetype to Get count of
Raises
TypeErroron type error
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 increment_count(self, mimetype):

Increment the count for the specified mimetype.

Parameters
mimetype:strmimetype to increase count of
Raises
TypeErroron type error
def on_install(self, zim, **kwargs):

Called when this processor is installed to a ZIM file.

By default, this sets BaseProcessor.zim.

Parameters
zim:pyzim.archive.ZimZIM archive this processor is installed on
**kwargs:dictextra keyword arguments
def to_string(self):

Dump the values of this counter into a string.

Returns
stra string that can be parsed into the counter value, compliant to the ZIM specification
counts: dict of str -> int =

a dict mapping mimetype to number of occurences

zim =

Undocumented

def _should_count_entry(self, entry):

Return True if the entry should be counted.

Parameters
entry:pyzim.entry.BaseEntryentry to count
Returns
boolwhether the entry should be counted or not