Skip to content

Commit 2fb30e0

Browse files
author
renaud gaudin
committed
Fixed #30: get_metadata() now returns bytes
mandatory metadata references gone, as per the spec
1 parent 70a74b1 commit 2fb30e0

File tree

3 files changed

+7
-38
lines changed

3 files changed

+7
-38
lines changed

libzim/wrapper.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ from libcpp.memory cimport shared_ptr, make_shared, unique_ptr
3131

3232
import datetime
3333

34+
3435
class NotFound(RuntimeError):
3536
pass
3637

@@ -407,14 +408,13 @@ cdef class FilePy:
407408
return article
408409

409410
def get_metadata(self, name):
410-
"""Get the file metadata.
411+
"""Get a metadata
411412
Returns
412413
-------
413-
dict
414-
A dictionary with the file metadata
414+
bytes
415+
Metadata article's content. Can be of any type.
415416
"""
416-
article = self.get_article(f"M/{name}")
417-
return article.content
417+
return bytes(self.get_article(f"M/{name}").content)
418418

419419
def get_article_by_id(self, article_id):
420420
"""Get a ZimFileArticle with a copy of the file article by article id.

libzim/writer.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ def get_data(self):
9898
return Blob(self.metadata_content)
9999

100100

101-
MANDATORY_METADATA_KEYS = [
102-
"Name",
103-
"Title",
104-
"Creator",
105-
"Publisher",
106-
"Date",
107-
"Description",
108-
"Language",
109-
]
110-
111-
112101
def pascalize(keyword):
113102
""" Converts python case to pascal case. example: long_description-> LongDescription """
114103
return "".join(keyword.title().split("_"))
@@ -165,13 +154,8 @@ def _update_article_counter(self, article):
165154
# default dict update
166155
self._article_counter[article.get_mime_type().strip()] += 1
167156

168-
def mandatory_metadata_ok(self):
169-
"""Flag if mandatory metadata is complete and not empty"""
170-
metadata_item_ok = [k in self._metadata for k in MANDATORY_METADATA_KEYS]
171-
return all(metadata_item_ok)
172-
173-
def update_metadata(self, **kwargs):
174-
"Updates article metadata" ""
157+
def update_metadata(self, **kwargs: str):
158+
""" Updates Creator metadata for ZIM, supplied as keyword arguments """
175159
new_metadata = {pascalize(k): v for k, v in kwargs.items()}
176160
self._metadata.update(new_metadata)
177161

tests/test_libzim.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,6 @@ def test_article_metadata(tmpdir, metadata):
128128
assert zim_creator._metadata == metadata
129129

130130

131-
def test_check_mandatory_metadata(tmpdir):
132-
with Creator(
133-
str(tmpdir / "test.zim"), main_page="welcome", index_language="eng", min_chunk_size=2048,
134-
) as zim_creator:
135-
assert not zim_creator.mandatory_metadata_ok()
136-
zim_creator.update_metadata(
137-
creator="python-libzim",
138-
description="Created in python",
139-
name="Hola",
140-
publisher="Monadical",
141-
title="Test Zim",
142-
)
143-
assert zim_creator.mandatory_metadata_ok()
144-
145-
146131
def test_creator_params(tmpdir):
147132
path = str(tmpdir / "test.zim")
148133
main_page = "welcome"

0 commit comments

Comments
 (0)