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 |
Initialize a counter from a string. |
| Class Method | load |
Initialize the counter from an existing archive. |
| Method | __init__ |
The default constructor. |
| Method | after |
Called during flush, after all content has been flushed. |
| Method | after |
Called after an entry has been removed. |
| Method | after |
Called after an entry was written. |
| Method | decrement |
Increment the count for the specified mimetype. |
| Method | get |
Get the count of a specific mimetype. |
| Method | get |
Calculate the size of this object when written to a file. |
| Method | increment |
Increment the count for the specified mimetype. |
| Method | on |
Called when this processor is installed to a ZIM file. |
| Method | to |
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 |
Return True if the entry should be counted. |
Inherited from ModifiableMixIn:
| Method | add |
Add another modifiable object as a child of this one. |
| 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 | 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. |
Inherited from BaseProcessor (via ModifiableMixIn):
| Method | after |
Called when the archive has been closed. |
| Method | after |
Called when pyzim.archive.Zim.get_cluster_at was called. |
| Method | after |
Called after a cluster has been written. |
| Method | after |
Called when pyzim.archive.Zim.get_entry_at was called, before the entry is returned. |
| Method | after |
Called after the archive has been flushed. |
| Method | before |
Called when the archive will be closed. |
| Method | before |
Called when pyzim.archive.Zim.get_cluster_at was called. |
| Method | before |
Called before a cluster will be written. |
| Method | before |
Called when pyzim.archive.Zim.get_entry_at was called. |
| Method | before |
Called before an entry will be removed. |
| Method | before |
Called before an entry will be written. |
| Method | before |
Called before the archive will be flushed. |
| Method | on |
Called when a redirect will be added. |
Initialize a counter from a string.
| Parameters | |
s:str or bytes | string to initialize from |
| Returns | |
Counter | the initialized counter |
| Raises | |
TypeError | on type error |
ValueError | on invalid value |
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
Noneif 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.Zim | ZIM archive to initialize from |
how:str | how to initialize the counter |
| Returns | |
Counter or None | a counter reflecting the mimetype count in the archive |
| Raises | |
TypeError | on invalid type |
ValueError | on invalid value |
Called during flush, after all content has been flushed.
At this point, the various pointerlists may not have yet been flushed.
| Parameters | |
**kwargs:dict | extra keyword arguments |
Called after an entry has been removed.
Keyword arguments:
- full_url (
str): full url of entry to remove - blob (
str): Seepyzim.archive.Zim.remove_entry_by_full_url - entry (
pyzim.entry.BaseEntry): entry that has been removed - is_article (
bool): whether the removed entry was an article or not.
| Parameters | |
**kwargs:dict | extra keyword arguments |
Called after an entry was written.
Keyword arguments:
- entry (
pyzim.entry.BaseEntry): entry that should be written - old_entry (
pyzim.entry.BaseEntryorNone): previous, unmodified entry, if any - old_offset (
intorNone): offset of old entry, if any - new_offset (
int): offset of new entry - is_new_entry (
bool): whether this is a new entry or not - add_to_title_pointer_list (
bool): Seepyzim.archive.Zim.write_entry - update_redirects (
bool): Seepyzim.archive.Zim.write_entry
| Parameters | |
**kwargs:dict | extra keyword arguments |
Increment the count for the specified mimetype.
| Parameters | |
mimetype:str | mimetype to increase count of |
| Raises | |
ValueError | if current count for mimetype is not at least 1 |
TypeError | on type error |
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 | |
int | the size, in bytes |
pyzim.processor.BaseProcessor.on_installCalled when this processor is installed to a ZIM file.
By default, this sets BaseProcessor.zim.
| Parameters | |
zim:pyzim.archive.Zim | ZIM archive this processor is installed on |
**kwargs:dict | extra keyword arguments |
Dump the values of this counter into a string.
| Returns | |
str | a string that can be parsed into the counter value, compliant to the ZIM specification |
Return True if the entry should be counted.
| Parameters | |
entry:pyzim.entry.BaseEntry | entry to count |
| Returns | |
bool | whether the entry should be counted or not |