Skip to content

remove metadata conversion #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions libzim/libzim.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,9 @@ class Creator(_Creator):
return super().config_compression(compression)

def add_metadata(
self, name: str, content: Union[str, bytes, datetime.date, datetime.datetime],
self, name: str, content: Union[str, bytes],
mimetype: str = "text/plain;charset=UTF-8"
):
if name == "Date" and isinstance(content, (datetime.date, datetime.datetime)):
content = content.strftime("%Y-%m-%d").encode("UTF-8")
if isinstance(content, str):
content = content.encode("UTF-8")
super().add_metadata(name=name, content=content, mimetype=mimetype)
Expand Down
6 changes: 0 additions & 6 deletions tests/test_libzim_creator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import base64
import datetime
import itertools
import os
import pathlib
Expand Down Expand Up @@ -400,13 +399,8 @@ def test_creator_metadata(fpath, lipsum_item):
with Creator(fpath) as c:
c.add_item(lipsum_item)
for name, value in metadata.items():
if name == "Date":
continue
c.add_metadata(name, value)

mdate = datetime.date(*[int(x) for x in metadata.get("Date").split("-")])
c.add_metadata("Date", mdate)

zim = Archive(fpath)
for name, value in metadata.items():
assert zim.get_metadata(name).decode("UTF-8") == value
Expand Down