@@ -254,6 +254,111 @@ class Hint(enum.Enum):
254254 FRONT_ARTICLE = zim.HintKeys.FRONT_ARTICLE
255255
256256
257+ class ContentProvider :
258+ """ ABC in charge of providing the content to add in the archive to the Creator."""
259+ __module__ = writer_module_name
260+ def __init__ (self ):
261+ self .generator = None
262+
263+ def get_size (self ) -> pyint:
264+ """Size of `get_data`'s result in bytes.
265+
266+ Returns:
267+ int: The size of the data in bytes.
268+ """
269+ raise NotImplementedError("get_size must be implemented.")
270+
271+ def feed(self ) -> WritingBlob:
272+ """Blob(s ) containing the complete content of the article.
273+
274+ Must return an empty blob to tell writer no more content has to be written.
275+ Sum(size(blobs )) must be equals to `self.get_size()`
276+
277+ Returns:
278+ WritingBlob: The content blob(s ) of the article.
279+ """
280+ if self.generator is None:
281+ self.generator = self .gen_blob()
282+
283+ try:
284+ # We have to keep a ref to _blob to be sure gc do not del it while cpp is
285+ # using it
286+ self._blob = next(self .generator)
287+ except StopIteration:
288+ self._blob = WritingBlob(" " )
289+
290+ return self._blob
291+
292+ def gen_blob(self ) -> Generator[WritingBlob , None , None]:
293+ """Generator yielding blobs for the content of the article.
294+
295+ Yields:
296+ WritingBlob: A blob containing part of the article content.
297+ """
298+ raise NotImplementedError("gen_blob (ro feed ) must be implemented")
299+
300+
301+ class BaseWritingItem:
302+ """
303+ Data to be added to the archive.
304+
305+ This is a stub to override. Pass a subclass of it to `Creator.add_item()`
306+ """
307+ __module__ = writer_module_name
308+
309+ def __init__(self ):
310+ self ._blob = None
311+ get_indexdata = None
312+
313+ def get_path (self ) -> str:
314+ """Full path of item.
315+
316+ The path must be absolute and unique.
317+
318+ Returns:
319+ Path of the item.
320+ """
321+ raise NotImplementedError("get_path must be implemented.")
322+
323+ def get_title(self ) -> str:
324+ """Item title. Might be indexed and used in suggestions.
325+
326+ Returns:
327+ Title of the item.
328+ """
329+ raise NotImplementedError("get_title must be implemented.")
330+
331+ def get_mimetype(self ) -> str:
332+ """MIME-type of the item's content.
333+
334+ Returns:
335+ Mimetype of the item.
336+ """
337+ raise NotImplementedError("get_mimetype must be implemented.")
338+
339+ def get_contentprovider(self ) -> ContentProvider:
340+ """ContentProvider containing the complete content of the item.
341+
342+ Returns:
343+ The content provider of the item.
344+ """
345+ raise NotImplementedError("get_contentprovider must be implemented.")
346+
347+ def get_hints(self ) -> Dict[Hint , pyint]:
348+ """Get the Hints that help the Creator decide how to handle this item.
349+
350+ Hints affects compression , presence in suggestion , random and search.
351+
352+ Returns:
353+ Hints to help the Creator decide how to handle this item.
354+ """
355+ raise NotImplementedError("get_hints must be implemented.")
356+
357+ def __repr__(self ) -> str:
358+ return (
359+ f"{self.__class__.__name__}(path = {self .get_path()}, "
360+ f"title = {self .get_title()})"
361+ )
257362
258363cdef class _Creator:
259364 """ZIM Creator.
@@ -283,7 +388,7 @@ cdef class _Creator:
283388 def __init__(self, filename: pathlib.Path):
284389 pass
285390
286- def config_verbose (self , bool verbose: bool ) -> Creator :
391+ def config_verbose(self, bool verbose: bool) -> _Creator :
287392 """ Set creator verbosity inside libzim (default: off).
288393
289394 Args:
@@ -297,7 +402,7 @@ cdef class _Creator:
297402 self.c_creator.configVerbose(verbose)
298403 return self
299404
300- def config_compression(self, compression: Compression) -> Creator :
405+ def config_compression(self, compression: Compression) -> _Creator :
301406 """ Set compression algorithm to use.
302407
303408 Check libzim for default setting. (Fall 2021 default: zstd).
@@ -313,7 +418,7 @@ cdef class _Creator:
313418 self.c_creator.configCompression(zim.comp_from_int(compression.value))
314419 return self
315420
316- def config_clustersize(self, int size: pyint) -> Creator :
421+ def config_clustersize(self, int size: pyint) -> _Creator :
317422 """ Set size of created clusters.
318423
319424 Check libzim for default setting. (Fall 2021 default: 2 Mib).
@@ -332,7 +437,7 @@ cdef class _Creator:
332437 self.c_creator.configClusterSize(size)
333438 return self
334439
335- def config_indexing(self, bool indexing: bool, str language: str) -> Creator :
440+ def config_indexing(self, bool indexing: bool, str language: str) -> _Creator :
336441 """ Configures the full- text indexing feature.
337442
338443 Args:
@@ -347,7 +452,7 @@ cdef class _Creator:
347452 self.c_creator.configIndexing(indexing, language.encode('UTF-8'))
348453 return self
349454
350- def config_nbworkers(self, int nbWorkers: pyint) -> Creator :
455+ def config_nbworkers(self, int nbWorkers: pyint) -> _Creator :
351456 """ Configures the number of threads to use for internal workers (default: 4 ).
352457
353458 Args:
@@ -361,7 +466,7 @@ cdef class _Creator:
361466 self.c_creator.configNbWorkers(nbWorkers)
362467 return self
363468
364- def set_mainpath(self, str mainPath: str) -> Creator :
469+ def set_mainpath(self, str mainPath: str) -> _Creator :
365470 """ Set path of the main entry.
366471
367472 Args:
@@ -388,7 +493,7 @@ cdef class _Creator:
388493 cdef string _content = content
389494 self.c_creator.addIllustration(size, _content)
390495
391- # def set_uuid(self, uuid) -> Creator :
496+ # def set_uuid(self, uuid) -> _Creator :
392497# self.c_creator.setUuid(uuid)
393498
394499 def add_item(self, writer_item not None: BaseWritingItem):
@@ -503,49 +608,6 @@ cdef class _Creator:
503608 """
504609 return self._filename
505610
506- class ContentProvider:
507- """ ABC in charge of providing the content to add in the archive to the Creator."""
508- __module__ = writer_module_name
509- def __init__(self):
510- self.generator = None
511-
512- def get_size(self) -> pyint:
513- """ Size of `get_data`' s result in bytes.
514-
515- Returns:
516- int : The size of the data in bytes.
517- """
518- raise NotImplementedError("get_size must be implemented.")
519-
520- def feed(self) -> WritingBlob:
521- """ Blob(s) containing the complete content of the article.
522-
523- Must return an empty blob to tell writer no more content has to be written.
524- Sum(size(blobs)) must be equals to `self .get_size()`
525-
526- Returns:
527- WritingBlob: The content blob(s) of the article.
528- """
529- if self.generator is None:
530- self.generator = self.gen_blob()
531-
532- try:
533- # We have to keep a ref to _blob to be sure gc do not del it while cpp is
534- # using it
535- self._blob = next(self.generator)
536- except StopIteration:
537- self._blob = WritingBlob("")
538-
539- return self._blob
540-
541- def gen_blob(self) -> Generator[WritingBlob, None, None]:
542- """ Generator yielding blobs for the content of the article.
543-
544- Yields:
545- WritingBlob: A blob containing part of the article content.
546- """
547- raise NotImplementedError("gen_blob (ro feed) must be implemented")
548-
549611
550612class StringProvider(ContentProvider):
551613 """ ContentProvider for a single encoded- or - not UTF- 8 string."""
@@ -644,69 +706,6 @@ class IndexData:
644706 return None
645707
646708
647- class BaseWritingItem:
648- """
649- Data to be added to the archive.
650-
651- This is a stub to override. Pass a subclass of it to `Creator.add_item()`
652- """
653- __module__ = writer_module_name
654-
655- def __init__(self):
656- self._blob = None
657- get_indexdata = None
658-
659- def get_path(self) -> str:
660- """ Full path of item.
661-
662- The path must be absolute and unique.
663-
664- Returns:
665- Path of the item.
666- """
667- raise NotImplementedError("get_path must be implemented.")
668-
669- def get_title(self) -> str:
670- """ Item title. Might be indexed and used in suggestions.
671-
672- Returns:
673- Title of the item.
674- """
675- raise NotImplementedError("get_title must be implemented.")
676-
677- def get_mimetype(self) -> str:
678- """ MIME- type of the item' s content.
679-
680- Returns:
681- Mimetype of the item.
682- """
683- raise NotImplementedError("get_mimetype must be implemented.")
684-
685- def get_contentprovider(self) -> ContentProvider:
686- """ ContentProvider containing the complete content of the item.
687-
688- Returns:
689- The content provider of the item.
690- """
691- raise NotImplementedError("get_contentprovider must be implemented.")
692-
693- def get_hints(self) -> Dict[Hint, pyint]:
694- """ Get the Hints that help the Creator decide how to handle this item.
695-
696- Hints affects compression, presence in suggestion, random and search.
697-
698- Returns:
699- Hints to help the Creator decide how to handle this item.
700- """
701- raise NotImplementedError("get_hints must be implemented.")
702-
703- def __repr__(self) -> str:
704- return (
705- f"{self.__class__.__name__}(path={self.get_path()}, "
706- f"title={self.get_title()})"
707- )
708-
709-
710709class Creator(_Creator):
711710 """ Creator to create ZIM files."""
712711 __module__ = writer_module_name
0 commit comments