Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions libzim/libzim.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ from libcpp.string cimport string
from libcpp cimport bool
from libcpp.memory cimport shared_ptr, make_shared

from contextlib import contextmanager


import datetime

Expand Down Expand Up @@ -345,7 +347,15 @@ cdef class ZimCreator:
def __repr__(self):
return f"{self.__class__.__name__}(filename={self.filename})"



@contextmanager
def zimcreator(*args, **kwds):
"""Context manager version of ZimCreator that calls .finalize() automatically on exit"""
zimcreator = ZimCreator(*args, **kwds)
try:
yield zimcreator
finally:
zimcreator.finalize()

#########################
# ZimFileArticle #
Expand Down Expand Up @@ -701,4 +711,4 @@ cdef class ZimFileReader:
return dereference(search).get_matches_estimated()

def __repr__(self):
return f"{self.__class__.__name__}(filename={self.filename})"
return f"{self.__class__.__name__}(filename={self.filename})"