Fix edition font UUID rebinding and Protocols translation layout
This commit is contained in:
+12
-1
@@ -16,6 +16,7 @@ from urllib.parse import quote, unquote, urlsplit
|
||||
from lxml import etree
|
||||
from src.common.html import parse_html
|
||||
from src.assembly.package_writer import package_path
|
||||
from src.edition.fonts import decoded_fonts
|
||||
from src.assembly.format_restorer import FormatRestorer
|
||||
from src.common.data_model import ManifestEntry
|
||||
from src.qa.epub_audit import audit_epub, compare_audits
|
||||
@@ -266,6 +267,15 @@ def audit_pair(source, translated, manifest=None, structure=None):
|
||||
def archive_server(paths):
|
||||
"""Serve allowlisted ZIP members on loopback, without extracting executable book data."""
|
||||
archives = {key: zipfile.ZipFile(path) for key, path in paths.items()}
|
||||
fonts = {}
|
||||
try:
|
||||
for key, archive in archives.items():
|
||||
opf_path = package_path(archive)
|
||||
root = etree.fromstring(archive.read(opf_path), etree.XMLParser(resolve_entities=False, no_network=True))
|
||||
fonts[key] = decoded_fonts(archive, opf_path, root)
|
||||
except Exception:
|
||||
for archive in archives.values(): archive.close()
|
||||
raise
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
@@ -274,7 +284,8 @@ def archive_server(paths):
|
||||
archive = archives.get(prefix)
|
||||
if not archive or name not in archive.namelist() or name.endswith('/'):
|
||||
self.send_error(404); return
|
||||
data = archive.read(name)
|
||||
data = fonts[prefix].get(name)
|
||||
if data is None: data = archive.read(name)
|
||||
mime = 'text/html' if name.lower().endswith(('.xhtml', '.html', '.htm')) else mimetypes.guess_type(name)[0] or 'application/octet-stream'
|
||||
self.send_response(200)
|
||||
self.send_header('Content-Type', mime + ('; charset=utf-8' if mime.startswith('text/') else ''))
|
||||
|
||||
Reference in New Issue
Block a user