diff options
| author | jvoisin <julien.voisin@dustri.org> | 2021-03-07 17:50:25 +0100 |
|---|---|---|
| committer | jvoisin <julien.voisin@dustri.org> | 2021-03-07 17:50:25 +0100 |
| commit | e2362b8620c1321fc93204a1830b60f48d3f43a2 (patch) | |
| tree | cf65b7ae9c6156fda085270f17fbc5a6cce39c7d | |
| parent | 626669f95f83f3e920966e8f82b301c269cdb1b3 (diff) | |
| download | external_mat2-e2362b8620c1321fc93204a1830b60f48d3f43a2.tar.gz external_mat2-e2362b8620c1321fc93204a1830b60f48d3f43a2.tar.bz2 external_mat2-e2362b8620c1321fc93204a1830b60f48d3f43a2.zip | |
Improve epub support
Warn when there are encrypted fonts in an epub file
| -rw-r--r-- | libmat2/epub.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/libmat2/epub.py b/libmat2/epub.py index 83f5728..af059d2 100644 --- a/libmat2/epub.py +++ b/libmat2/epub.py @@ -1,6 +1,7 @@ import logging import re import uuid +import zipfile import xml.etree.ElementTree as ET # type: ignore from typing import Dict, Any @@ -27,7 +28,16 @@ class EPUBParser(archive.ZipParser): })) self.uniqid = uuid.uuid4() - def _specific_get_meta(self, full_path, file_path): + + def is_archive_valid(self): + super().is_archive_valid() + with zipfile.ZipFile(self.filename) as zin: + for item in self._get_all_members(zin): + member_name = self._get_member_name(item) + if member_name.endswith('META-INF/encryption.xml'): + raise ValueError('the file contains encrypted fonts') + + def _specific_get_meta(self, full_path, file_path) -> Dict[str, Any]: if not file_path.endswith('.opf'): return {} |
