class documentation

This class represents a MIME type list.

The MIME type list contains an index->mimetype mapping. Each distinct mimetype used by entries is contained in the MIME type list. The entries themselves only contain the index of the MIME type in this list.

Class Method from_file Read the mime type list from a file.
Method __init__ The default constructor.
Method __len__ The length of this mimetype list.
Method __str__ Return a string displaying the content of the mimetypelist.
Method get Return the mimetype for the specified index.
Method get_disk_size Calculate the size of this object when written to a file.
Method get_index Return the index for the specified mimetype.
Method has Check if this mimetypelist has the specified mimetype.
Method iter_mimetypes Iterate over all mimetypes in this list.
Method register Register a mimetype in a thread-safe manner.
Method to_bytes Dump this mime type list into a a bytestring.
Instance Variable _lock thread safety lock
Instance Variable _mimetypes (ordered) list of mimetypes in this object

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.
def from_file(cls, f, seek=None):

Read the mime type list from a file.

Parameters
f:file-likefile-like object to read from
seek:int or Noneif specified, seek this position
Returns
pyzim.mimetypelist.MimeTypeListthe mimetypelist read from the file
def __init__(self, mimetypes):

The default constructor.

Parameters
mimetypes:list of byteslist of mimetypes. Order matters!
def __len__(self):

The length of this mimetype list.

Returns
intthe length of this mimetype list
def __str__(self):

Return a string displaying the content of the mimetypelist.

Returns
stra string describing the content of the mimetypelist
def get(self, i, as_unicode=False):

Return the mimetype for the specified index.

Parameters
i:intindex of mimetype to get
as_unicode:boolif nonzero, decode as unicode
Returns
bytes or str if as_unicode is nonzerothe mimetype, as bytes
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 get_index(self, mimetype, register=False):

Return the index for the specified mimetype.

Parameters
mimetype:str or bytesmimetype to get index for
register:boolif nonzero and the mimetype was not found, register it
Returns
int or None if not found and register is not truethe index of the mimetype, None if not found and register is false
def has(self, mimetype):

Check if this mimetypelist has the specified mimetype.

Parameters
mimetype:bytes or strmimetype to check
Returns
boolTrue if the mimetypelist has the specified mimetype, False otherwise
def iter_mimetypes(self, as_unicode=False):

Iterate over all mimetypes in this list.

Parameters
as_unicode:boolif nonzero, decode mimetypes
Yields
bytes or str if as_unicode is nonzerothe mimetypes in this mimetype list
def register(self, mimetype):

Register a mimetype in a thread-safe manner.

Multiple registrations will be ignored, but should be avoided as the registration process in inefficient due to the lock.

Parameters
mimetype:str or bytesmimetype to register
Raises
pyzim.exceptions.NonMutableif mimetype list is not mutable
def to_bytes(self):

Dump this mime type list into a a bytestring.

Returns
bytesa bytestring containing this mimetypelist.

thread safety lock

_mimetypes: list of bytes =

(ordered) list of mimetypes in this object