docvortex 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docvortex/__init__.py +21 -0
- docvortex/analyzers/__init__.py +3 -0
- docvortex/analyzers/native/__init__.py +37 -0
- docvortex/analyzers/native/_shared/__init__.py +3 -0
- docvortex/analyzers/native/_shared/hyperlink.py +16 -0
- docvortex/analyzers/native/_shared/image.py +8 -0
- docvortex/analyzers/native/_shared/markup/__init__.py +47 -0
- docvortex/analyzers/native/_shared/markup/anchors.py +30 -0
- docvortex/analyzers/native/_shared/markup/formula.py +37 -0
- docvortex/analyzers/native/_shared/markup/projector.py +57 -0
- docvortex/analyzers/native/_shared/markup/styles.py +19 -0
- docvortex/analyzers/native/_shared/mathml.py +17 -0
- docvortex/analyzers/native/_shared/names.py +7 -0
- docvortex/analyzers/native/_shared/xycut.py +414 -0
- docvortex/analyzers/native/contracts.py +44 -0
- docvortex/analyzers/native/csv.py +351 -0
- docvortex/analyzers/native/epub/__init__.py +18 -0
- docvortex/analyzers/native/epub/constants.py +45 -0
- docvortex/analyzers/native/epub/converter.py +80 -0
- docvortex/analyzers/native/epub/errors.py +20 -0
- docvortex/analyzers/native/epub/metadata.py +31 -0
- docvortex/analyzers/native/epub/package.py +649 -0
- docvortex/analyzers/native/epub/xhtml.py +306 -0
- docvortex/analyzers/native/html/__init__.py +6 -0
- docvortex/analyzers/native/html/anchors.py +271 -0
- docvortex/analyzers/native/html/constants.py +25 -0
- docvortex/analyzers/native/html/contracts.py +7 -0
- docvortex/analyzers/native/html/converter.py +117 -0
- docvortex/analyzers/native/html/document.py +389 -0
- docvortex/analyzers/native/html/errors.py +12 -0
- docvortex/analyzers/native/html/resources.py +365 -0
- docvortex/analyzers/native/html/selector.py +421 -0
- docvortex/analyzers/native/models.py +209 -0
- docvortex/analyzers/native/ofd/__init__.py +14 -0
- docvortex/analyzers/native/ofd/constants.py +59 -0
- docvortex/analyzers/native/ofd/converter.py +31 -0
- docvortex/analyzers/native/ofd/errors.py +16 -0
- docvortex/analyzers/native/ofd/geometry.py +215 -0
- docvortex/analyzers/native/ofd/images.py +124 -0
- docvortex/analyzers/native/ofd/metadata.py +53 -0
- docvortex/analyzers/native/ofd/models.py +170 -0
- docvortex/analyzers/native/ofd/package.py +346 -0
- docvortex/analyzers/native/ofd/path.py +201 -0
- docvortex/analyzers/native/ofd/reading_order.py +293 -0
- docvortex/analyzers/native/ofd/resources.py +122 -0
- docvortex/analyzers/native/ofd/scene.py +347 -0
- docvortex/analyzers/native/ofd/table.py +240 -0
- docvortex/analyzers/native/ofd/text.py +521 -0
- docvortex/analyzers/native/office/__init__.py +3 -0
- docvortex/analyzers/native/office/doc/__init__.py +3 -0
- docvortex/analyzers/native/office/doc/bookmarks.py +81 -0
- docvortex/analyzers/native/office/doc/doc_converter.py +573 -0
- docvortex/analyzers/native/office/doc/fib.py +261 -0
- docvortex/analyzers/native/office/doc/fields.py +101 -0
- docvortex/analyzers/native/office/doc/formatting.py +171 -0
- docvortex/analyzers/native/office/doc/images.py +162 -0
- docvortex/analyzers/native/office/doc/lists.py +356 -0
- docvortex/analyzers/native/office/doc/models.py +164 -0
- docvortex/analyzers/native/office/doc/parser.py +851 -0
- docvortex/analyzers/native/office/doc/pieces.py +256 -0
- docvortex/analyzers/native/office/doc/records.py +40 -0
- docvortex/analyzers/native/office/doc/sprm.py +269 -0
- docvortex/analyzers/native/office/doc/styles.py +215 -0
- docvortex/analyzers/native/office/docx/__init__.py +3 -0
- docvortex/analyzers/native/office/docx/context.py +71 -0
- docvortex/analyzers/native/office/docx/docx_converter.py +614 -0
- docvortex/analyzers/native/office/docx/equationxml.py +119 -0
- docvortex/analyzers/native/office/docx/fields.py +816 -0
- docvortex/analyzers/native/office/docx/formatting_types.py +23 -0
- docvortex/analyzers/native/office/docx/main.py +50 -0
- docvortex/analyzers/native/office/docx/numbering.py +491 -0
- docvortex/analyzers/native/office/docx/office_xml.py +57 -0
- docvortex/analyzers/native/office/docx/package_normalizer.py +248 -0
- docvortex/analyzers/native/office/docx/resources.py +526 -0
- docvortex/analyzers/native/office/docx/styles.py +693 -0
- docvortex/analyzers/native/office/docx/tables.py +515 -0
- docvortex/analyzers/native/office/equation/__init__.py +3 -0
- docvortex/analyzers/native/office/equation/image.py +470 -0
- docvortex/analyzers/native/office/equation/latex_dict.py +324 -0
- docvortex/analyzers/native/office/equation/mtef.py +885 -0
- docvortex/analyzers/native/office/equation/mtef_v5.py +941 -0
- docvortex/analyzers/native/office/equation/omml.py +561 -0
- docvortex/analyzers/native/office/equation/ooxml.py +62 -0
- docvortex/analyzers/native/office/errors.py +33 -0
- docvortex/analyzers/native/office/image.py +307 -0
- docvortex/analyzers/native/office/legacy/__init__.py +3 -0
- docvortex/analyzers/native/office/legacy/binary.py +43 -0
- docvortex/analyzers/native/office/legacy/officeart.py +362 -0
- docvortex/analyzers/native/office/legacy/ole.py +110 -0
- docvortex/analyzers/native/office/limits.py +12 -0
- docvortex/analyzers/native/office/odf/__init__.py +3 -0
- docvortex/analyzers/native/office/odf/chart.py +76 -0
- docvortex/analyzers/native/office/odf/constants.py +70 -0
- docvortex/analyzers/native/office/odf/converters.py +403 -0
- docvortex/analyzers/native/office/odf/errors.py +18 -0
- docvortex/analyzers/native/office/odf/metadata.py +91 -0
- docvortex/analyzers/native/office/odf/models.py +176 -0
- docvortex/analyzers/native/office/odf/package.py +270 -0
- docvortex/analyzers/native/office/odf/styles.py +329 -0
- docvortex/analyzers/native/office/odf/table.py +469 -0
- docvortex/analyzers/native/office/odf/text.py +1002 -0
- docvortex/analyzers/native/office/ooxml_chart.py +1016 -0
- docvortex/analyzers/native/office/opc.py +38 -0
- docvortex/analyzers/native/office/ppt/__init__.py +3 -0
- docvortex/analyzers/native/office/ppt/models.py +118 -0
- docvortex/analyzers/native/office/ppt/parser.py +1895 -0
- docvortex/analyzers/native/office/ppt/ppt_converter.py +292 -0
- docvortex/analyzers/native/office/ppt/records.py +131 -0
- docvortex/analyzers/native/office/ppt/style_text.py +247 -0
- docvortex/analyzers/native/office/pptx/__init__.py +3 -0
- docvortex/analyzers/native/office/pptx/context.py +113 -0
- docvortex/analyzers/native/office/pptx/lists.py +558 -0
- docvortex/analyzers/native/office/pptx/main.py +20 -0
- docvortex/analyzers/native/office/pptx/package_normalizer.py +321 -0
- docvortex/analyzers/native/office/pptx/pptx_converter.py +323 -0
- docvortex/analyzers/native/office/pptx/resources.py +329 -0
- docvortex/analyzers/native/office/pptx/shapes.py +393 -0
- docvortex/analyzers/native/office/pptx/text_styles.py +625 -0
- docvortex/analyzers/native/office/pptx/titles.py +178 -0
- docvortex/analyzers/native/office/rich_text.py +420 -0
- docvortex/analyzers/native/office/rtf/__init__.py +3 -0
- docvortex/analyzers/native/office/rtf/converter.py +708 -0
- docvortex/analyzers/native/office/rtf/lexer.py +213 -0
- docvortex/analyzers/native/office/rtf/math.py +339 -0
- docvortex/analyzers/native/office/rtf/models.py +185 -0
- docvortex/analyzers/native/office/rtf/parser.py +1553 -0
- docvortex/analyzers/native/office/spreadsheet/__init__.py +3 -0
- docvortex/analyzers/native/office/spreadsheet/html.py +81 -0
- docvortex/analyzers/native/office/spreadsheet/models.py +79 -0
- docvortex/analyzers/native/office/spreadsheet/projector.py +928 -0
- docvortex/analyzers/native/office/streams.py +18 -0
- docvortex/analyzers/native/office/xls/__init__.py +3 -0
- docvortex/analyzers/native/office/xls/chart.py +132 -0
- docvortex/analyzers/native/office/xls/embedded_chart.py +299 -0
- docvortex/analyzers/native/office/xls/models.py +109 -0
- docvortex/analyzers/native/office/xls/number_format.py +521 -0
- docvortex/analyzers/native/office/xls/parser.py +1145 -0
- docvortex/analyzers/native/office/xls/records.py +201 -0
- docvortex/analyzers/native/office/xls/strings.py +205 -0
- docvortex/analyzers/native/office/xls/xls_converter.py +354 -0
- docvortex/analyzers/native/office/xlsx/__init__.py +3 -0
- docvortex/analyzers/native/office/xlsx/main.py +20 -0
- docvortex/analyzers/native/office/xlsx/ooxml_ole.py +522 -0
- docvortex/analyzers/native/office/xlsx/package_normalizer.py +310 -0
- docvortex/analyzers/native/office/xlsx/xlsx_converter.py +716 -0
- docvortex/analyzers/native/pdf/__init__.py +3 -0
- docvortex/analyzers/native/pdf/auxiliary_text.py +1671 -0
- docvortex/analyzers/native/pdf/char_geometry.py +1662 -0
- docvortex/analyzers/native/pdf/code_blocks.py +535 -0
- docvortex/analyzers/native/pdf/formulas.py +1985 -0
- docvortex/analyzers/native/pdf/geometry.py +281 -0
- docvortex/analyzers/native/pdf/graphics.py +1501 -0
- docvortex/analyzers/native/pdf/index_blocks.py +268 -0
- docvortex/analyzers/native/pdf/inline/__init__.py +3 -0
- docvortex/analyzers/native/pdf/inline/common.py +112 -0
- docvortex/analyzers/native/pdf/inline/detection.py +590 -0
- docvortex/analyzers/native/pdf/inline/matching.py +1185 -0
- docvortex/analyzers/native/pdf/inline/materialize.py +457 -0
- docvortex/analyzers/native/pdf/inline/scripts.py +975 -0
- docvortex/analyzers/native/pdf/inline/types.py +385 -0
- docvortex/analyzers/native/pdf/line_layout.py +1106 -0
- docvortex/analyzers/native/pdf/line_merging.py +1223 -0
- docvortex/analyzers/native/pdf/models.py +246 -0
- docvortex/analyzers/native/pdf/native_text.py +1004 -0
- docvortex/analyzers/native/pdf/pipeline.py +1390 -0
- docvortex/analyzers/native/pdf/script_geometry.py +636 -0
- docvortex/analyzers/native/pdf/shared.py +30 -0
- docvortex/analyzers/native/pdf/spatial_text.py +383 -0
- docvortex/analyzers/native/pdf/table_annotations.py +446 -0
- docvortex/analyzers/native/pdf/table_constants.py +48 -0
- docvortex/analyzers/native/pdf/table_detection.py +227 -0
- docvortex/analyzers/native/pdf/table_filled_grid.py +218 -0
- docvortex/analyzers/native/pdf/table_geometry.py +40 -0
- docvortex/analyzers/native/pdf/table_materialization.py +444 -0
- docvortex/analyzers/native/pdf/table_recovery/__init__.py +15 -0
- docvortex/analyzers/native/pdf/table_recovery/candidate.py +356 -0
- docvortex/analyzers/native/pdf/table_recovery/contracts.py +154 -0
- docvortex/analyzers/native/pdf/table_recovery/engine.py +609 -0
- docvortex/analyzers/native/pdf/table_recovery/geometry.py +164 -0
- docvortex/analyzers/native/pdf/table_recovery/sparse_common.py +85 -0
- docvortex/analyzers/native/pdf/table_recovery/sparse_hybrid.py +804 -0
- docvortex/analyzers/native/pdf/table_recovery/sparse_multiline.py +1122 -0
- docvortex/analyzers/native/pdf/table_recovery/text.py +414 -0
- docvortex/analyzers/native/pdf/table_recovery/text_grid.py +618 -0
- docvortex/analyzers/native/pdf/table_recovery/vector.py +1931 -0
- docvortex/analyzers/native/pdf/table_rows.py +34 -0
- docvortex/analyzers/native/pdf/table_rules.py +1129 -0
- docvortex/analyzers/native/pdf/table_text_styles.py +283 -0
- docvortex/analyzers/native/pdf/tables.py +147 -0
- docvortex/analyzers/native/pdf/text_assembly/__init__.py +3 -0
- docvortex/analyzers/native/pdf/text_assembly/annotations.py +581 -0
- docvortex/analyzers/native/pdf/text_assembly/assembly.py +292 -0
- docvortex/analyzers/native/pdf/text_assembly/common.py +477 -0
- docvortex/analyzers/native/pdf/text_assembly/footnotes.py +394 -0
- docvortex/analyzers/native/pdf/text_assembly/merging.py +1274 -0
- docvortex/analyzers/native/pdf/text_assembly/rows.py +692 -0
- docvortex/analyzers/native/pdf/text_blocks.py +82 -0
- docvortex/analyzers/native/pdf/text_styles.py +55 -0
- docvortex/analyzers/native/pdf/title_analysis/__init__.py +3 -0
- docvortex/analyzers/native/pdf/title_analysis/body_profile.py +215 -0
- docvortex/analyzers/native/pdf/title_analysis/common.py +117 -0
- docvortex/analyzers/native/pdf/title_analysis/document_profile.py +164 -0
- docvortex/analyzers/native/pdf/title_analysis/lane_titles.py +758 -0
- docvortex/analyzers/native/pdf/title_analysis/page_titles.py +1024 -0
- docvortex/analyzers/native/pdf/title_analysis/prototype.py +194 -0
- docvortex/analyzers/native/pdf/title_analysis/structural.py +1081 -0
- docvortex/analyzers/native/pdf/titles.py +75 -0
- docvortex/analyzers/native/pdf/typography.py +19 -0
- docvortex/analyzers/native/pdf/visual_annotations.py +1262 -0
- docvortex/api.py +180 -0
- docvortex/assets/__init__.py +5 -0
- docvortex/assets/store.py +51 -0
- docvortex/cli.py +54 -0
- docvortex/codecs/__init__.py +3 -0
- docvortex/codecs/html/__init__.py +22 -0
- docvortex/codecs/html/contracts.py +236 -0
- docvortex/codecs/html/materializer.py +331 -0
- docvortex/codecs/html/parser.py +763 -0
- docvortex/codecs/html/resources.py +34 -0
- docvortex/codecs/json.py +17 -0
- docvortex/content/__init__.py +5 -0
- docvortex/content/inline.py +248 -0
- docvortex/content/markup/__init__.py +44 -0
- docvortex/content/markup/anchors.py +188 -0
- docvortex/content/markup/formula.py +280 -0
- docvortex/content/markup/projector.py +1237 -0
- docvortex/content/markup/styles.py +327 -0
- docvortex/content/mathml.py +167 -0
- docvortex/content/normalization.py +188 -0
- docvortex/content/spans.py +183 -0
- docvortex/content/table/__init__.py +18 -0
- docvortex/content/table/blocks.py +152 -0
- docvortex/content/table/content.py +425 -0
- docvortex/content/table/document.py +104 -0
- docvortex/content/table/html.py +399 -0
- docvortex/content/table/models.py +76 -0
- docvortex/content/table/rules.py +42 -0
- docvortex/content/table/structure.py +221 -0
- docvortex/content/tree.py +5 -0
- docvortex/document/__init__.py +3 -0
- docvortex/document/contracts.py +22 -0
- docvortex/document/detection.py +389 -0
- docvortex/document/filetypes.py +175 -0
- docvortex/document/page_range.py +167 -0
- docvortex/document/pdf/__init__.py +19 -0
- docvortex/document/pdf/classify.py +1138 -0
- docvortex/document/pdf/constants.py +132 -0
- docvortex/document/pdf/diagnostics.py +350 -0
- docvortex/document/pdf/document.py +582 -0
- docvortex/document/pdf/font_runtime.py +335 -0
- docvortex/document/pdf/geometry.py +31 -0
- docvortex/document/pdf/images.py +654 -0
- docvortex/document/pdf/native_annotations.py +367 -0
- docvortex/document/pdf/native_contracts.py +169 -0
- docvortex/document/pdf/native_coordinates.py +216 -0
- docvortex/document/pdf/native_lifecycle.py +16 -0
- docvortex/document/pdf/native_objects.py +902 -0
- docvortex/document/pdf/native_text_geometry.py +315 -0
- docvortex/document/pdf/pdfium.py +325 -0
- docvortex/document/pdf/raster.py +46 -0
- docvortex/document/pdf/text/__init__.py +62 -0
- docvortex/document/pdf/text/contracts.py +211 -0
- docvortex/document/pdf/text/extract.py +165 -0
- docvortex/document/pdf/text/geometry.py +16 -0
- docvortex/document/pdf/text/groups.py +162 -0
- docvortex/document/pdf/visual_geometry.py +201 -0
- docvortex/document/pdf/visuals.py +343 -0
- docvortex/document/source.py +92 -0
- docvortex/errors.py +21 -0
- docvortex/export/__init__.py +3 -0
- docvortex/export/bundle.py +98 -0
- docvortex/export/files.py +66 -0
- docvortex/export/middle.py +208 -0
- docvortex/foundation/__init__.py +3 -0
- docvortex/foundation/geometry.py +125 -0
- docvortex/foundation/hyperlink.py +65 -0
- docvortex/foundation/image.py +48 -0
- docvortex/foundation/image_encoding.py +30 -0
- docvortex/foundation/image_payload.py +280 -0
- docvortex/foundation/language.py +92 -0
- docvortex/foundation/platform.py +38 -0
- docvortex/foundation/text.py +153 -0
- docvortex/foundation/type_identity.py +20 -0
- docvortex/foundation/xml_names.py +20 -0
- docvortex/options.py +30 -0
- docvortex/postprocess/__init__.py +3 -0
- docvortex/postprocess/content.py +53 -0
- docvortex/postprocess/document.py +19 -0
- docvortex/postprocess/lists.py +236 -0
- docvortex/postprocess/page_blocks.py +214 -0
- docvortex/postprocess/pages.py +95 -0
- docvortex/postprocess/paragraphs.py +580 -0
- docvortex/postprocess/visual.py +715 -0
- docvortex/render/__init__.py +48 -0
- docvortex/render/_internal/__init__.py +3 -0
- docvortex/render/_internal/common/__init__.py +3 -0
- docvortex/render/_internal/common/context.py +43 -0
- docvortex/render/_internal/common/html_table.py +178 -0
- docvortex/render/_internal/common/index.py +33 -0
- docvortex/render/_internal/common/list_items.py +158 -0
- docvortex/render/_internal/common/planner.py +140 -0
- docvortex/render/_internal/docx/__init__.py +3 -0
- docvortex/render/_internal/docx/assets.py +202 -0
- docvortex/render/_internal/docx/inline.py +434 -0
- docvortex/render/_internal/docx/math.py +220 -0
- docvortex/render/_internal/docx/renderer.py +905 -0
- docvortex/render/_internal/docx/styles.py +195 -0
- docvortex/render/_internal/docx/table.py +442 -0
- docvortex/render/_internal/epub/__init__.py +5 -0
- docvortex/render/_internal/epub/assets.py +173 -0
- docvortex/render/_internal/epub/package.py +249 -0
- docvortex/render/_internal/epub/renderer.py +1156 -0
- docvortex/render/_internal/html/__init__.py +3 -0
- docvortex/render/_internal/html/inline.py +346 -0
- docvortex/render/_internal/html/renderer.py +1041 -0
- docvortex/render/_internal/html/sanitizer.py +478 -0
- docvortex/render/_internal/html/table.py +121 -0
- docvortex/render/_internal/latex/__init__.py +1 -0
- docvortex/render/_internal/latex/assets.py +85 -0
- docvortex/render/_internal/latex/inline.py +145 -0
- docvortex/render/_internal/latex/renderer.py +506 -0
- docvortex/render/_internal/latex/table.py +347 -0
- docvortex/render/_internal/markdown/__init__.py +3 -0
- docvortex/render/_internal/markdown/assets.py +78 -0
- docvortex/render/_internal/markdown/blocks.py +635 -0
- docvortex/render/_internal/markdown/escaping.py +51 -0
- docvortex/render/_internal/markdown/inline.py +260 -0
- docvortex/render/_internal/markdown/renderer.py +93 -0
- docvortex/render/_internal/markdown/table.py +281 -0
- docvortex/render/_internal/pdf/__init__.py +3 -0
- docvortex/render/_internal/pdf/assets.py +197 -0
- docvortex/render/_internal/pdf/formula.py +417 -0
- docvortex/render/_internal/pdf/inline.py +343 -0
- docvortex/render/_internal/pdf/renderer.py +734 -0
- docvortex/render/_internal/pdf/styles.py +206 -0
- docvortex/render/_internal/pdf/table.py +272 -0
- docvortex/render/_internal/structured_content/__init__.py +3 -0
- docvortex/render/_internal/structured_content/renderer.py +193 -0
- docvortex/render/api.py +199 -0
- docvortex/render/contracts.py +205 -0
- docvortex/render/docx.py +38 -0
- docvortex/render/epub.py +35 -0
- docvortex/render/fragments.py +70 -0
- docvortex/render/html.py +29 -0
- docvortex/render/latex.py +24 -0
- docvortex/render/markdown.py +50 -0
- docvortex/render/pdf.py +25 -0
- docvortex/render/structured_content.py +23 -0
- docvortex/resources/epub/docvortex.css +91 -0
- docvortex/resources/fasttext-langdetect/lid.176.ftz +0 -0
- docvortex/resources/fonts/DroidSansFallbackFull.ttf +0 -0
- docvortex/resources/fonts/NOTICE +190 -0
- docvortex/resources/fonts/manifest.json +9 -0
- docvortex/resources/html/docvortex.css +601 -0
- docvortex/resources/html/docvortex.min.css +1 -0
- docvortex/result.py +91 -0
- docvortex/schema.py +1141 -0
- docvortex/version.py +3 -0
- docvortex-0.2.1.dist-info/METADATA +193 -0
- docvortex-0.2.1.dist-info/RECORD +364 -0
- docvortex-0.2.1.dist-info/WHEEL +5 -0
- docvortex-0.2.1.dist-info/entry_points.txt +2 -0
- docvortex-0.2.1.dist-info/licenses/LICENSE.md +21 -0
- docvortex-0.2.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""EPUB renderer 的图片解析、规范化与包内去重。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
import hashlib
|
|
7
|
+
from io import BytesIO
|
|
8
|
+
from pathlib import PurePosixPath
|
|
9
|
+
import re
|
|
10
|
+
from urllib.parse import unquote, urlsplit
|
|
11
|
+
|
|
12
|
+
from PIL import Image, UnidentifiedImageError
|
|
13
|
+
|
|
14
|
+
from ...contracts import AssetResolver
|
|
15
|
+
from ....schema import ImagePayloadBlock
|
|
16
|
+
from ....foundation.image_payload import (
|
|
17
|
+
MAX_IMAGE_DATA_URI_BYTES,
|
|
18
|
+
MAX_IMAGE_PAYLOAD_BYTES,
|
|
19
|
+
extract_generated_svg_fallback,
|
|
20
|
+
normalize_image_extension,
|
|
21
|
+
parse_image_data_uri_strict,
|
|
22
|
+
validate_decoded_raster_size,
|
|
23
|
+
validate_image_sidecar_path,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
_SVG_START_RE = re.compile(rb"^(?:\xef\xbb\xbf)?\s*(?:<\?xml\b.*?\?>\s*)?<svg\b", re.IGNORECASE | re.DOTALL)
|
|
27
|
+
_PASSTHROUGH_FORMATS = {"gif", "jpg", "png"}
|
|
28
|
+
_MEDIA_TYPES = {
|
|
29
|
+
"gif": "image/gif",
|
|
30
|
+
"jpg": "image/jpeg",
|
|
31
|
+
"png": "image/png",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True, slots=True)
|
|
36
|
+
class EpubAsset:
|
|
37
|
+
"""保存一个已规范化且可写入 EPUB 的图片资源。"""
|
|
38
|
+
|
|
39
|
+
file_name: str
|
|
40
|
+
media_type: str
|
|
41
|
+
data: bytes
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class EpubAssetRegistry:
|
|
45
|
+
"""按内容哈希登记 EPUB 图片,并隔离所有外部素材读取。"""
|
|
46
|
+
|
|
47
|
+
def __init__(self, asset_resolver: AssetResolver | None) -> None:
|
|
48
|
+
"""保存显式 resolver,并初始化来源缓存与内容去重表。"""
|
|
49
|
+
self._asset_resolver = asset_resolver
|
|
50
|
+
self._source_cache: dict[str, str | None] = {}
|
|
51
|
+
self._assets: dict[str, EpubAsset] = {}
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def assets(self) -> tuple[EpubAsset, ...]:
|
|
55
|
+
"""按稳定文件名顺序返回所有已登记包内图片。"""
|
|
56
|
+
return tuple(self._assets[name] for name in sorted(self._assets))
|
|
57
|
+
|
|
58
|
+
def resolve_block(self, block: ImagePayloadBlock) -> str | None:
|
|
59
|
+
"""按 sidecar、data URI、远程 URL 优先级解析一个图片 block。"""
|
|
60
|
+
if block.image_path:
|
|
61
|
+
resolved = self._resolve_relative_path(block.image_path)
|
|
62
|
+
if resolved is not None:
|
|
63
|
+
return resolved
|
|
64
|
+
if block.image_base64:
|
|
65
|
+
resolved = self._resolve_data_uri(block.image_base64)
|
|
66
|
+
if resolved is not None:
|
|
67
|
+
return resolved
|
|
68
|
+
# EPUB 图片必须位于容器中;远程 image_url 只作为不可下载的最后候选跳过。
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
def resolve_embedded_source(self, source: str) -> str | None:
|
|
72
|
+
"""解析富 HTML img 的 data URI 或安全相对 sidecar,拒绝网络来源。"""
|
|
73
|
+
normalized = source.strip()
|
|
74
|
+
if not normalized:
|
|
75
|
+
return None
|
|
76
|
+
if normalized.lower().startswith("data:"):
|
|
77
|
+
return self._resolve_data_uri(normalized)
|
|
78
|
+
try:
|
|
79
|
+
parsed = urlsplit(normalized)
|
|
80
|
+
except ValueError:
|
|
81
|
+
return None
|
|
82
|
+
if parsed.scheme or parsed.netloc or parsed.query or parsed.fragment or normalized.startswith(("/", "\\")):
|
|
83
|
+
return None
|
|
84
|
+
decoded_path = unquote(parsed.path)
|
|
85
|
+
try:
|
|
86
|
+
safe_path = validate_image_sidecar_path(decoded_path)
|
|
87
|
+
except ValueError:
|
|
88
|
+
return None
|
|
89
|
+
return self._resolve_relative_path(safe_path)
|
|
90
|
+
|
|
91
|
+
def _resolve_relative_path(self, image_path: str) -> str | None:
|
|
92
|
+
"""通过显式 resolver 读取相对图片,失败时返回可降级的空结果。"""
|
|
93
|
+
cache_key = f"path:{image_path}"
|
|
94
|
+
if cache_key in self._source_cache:
|
|
95
|
+
return self._source_cache[cache_key]
|
|
96
|
+
if self._asset_resolver is None:
|
|
97
|
+
self._source_cache[cache_key] = None
|
|
98
|
+
return None
|
|
99
|
+
try:
|
|
100
|
+
safe_path = validate_image_sidecar_path(image_path)
|
|
101
|
+
data = self._asset_resolver(safe_path)
|
|
102
|
+
if not isinstance(data, bytes):
|
|
103
|
+
raise TypeError("asset_resolver must return bytes")
|
|
104
|
+
declared_extension = PurePosixPath(safe_path).suffix.removeprefix(".") or None
|
|
105
|
+
href = self._register_prepared(data, declared_extension=declared_extension)
|
|
106
|
+
except Exception:
|
|
107
|
+
href = None
|
|
108
|
+
self._source_cache[cache_key] = href
|
|
109
|
+
return href
|
|
110
|
+
|
|
111
|
+
def _resolve_data_uri(self, data_uri: str) -> str | None:
|
|
112
|
+
"""严格解码图片 data URI,失败时返回可降级的空结果。"""
|
|
113
|
+
if len(data_uri) > MAX_IMAGE_DATA_URI_BYTES:
|
|
114
|
+
return None
|
|
115
|
+
cache_key = f"data:{hashlib.sha256(data_uri.encode('utf-8', errors='replace')).hexdigest()}"
|
|
116
|
+
if cache_key in self._source_cache:
|
|
117
|
+
return self._source_cache[cache_key]
|
|
118
|
+
try:
|
|
119
|
+
data, extension = parse_image_data_uri_strict(data_uri)
|
|
120
|
+
href = self._register_prepared(data, declared_extension=extension)
|
|
121
|
+
except (OSError, TypeError, ValueError):
|
|
122
|
+
href = None
|
|
123
|
+
self._source_cache[cache_key] = href
|
|
124
|
+
return href
|
|
125
|
+
|
|
126
|
+
def _register_prepared(self, data: bytes, *, declared_extension: str | None) -> str:
|
|
127
|
+
"""规范化图片格式,按 SHA-256 去重并返回正文相对 href。"""
|
|
128
|
+
normalized, extension = _prepare_epub_image(data, declared_extension=declared_extension)
|
|
129
|
+
digest = hashlib.sha256(normalized).hexdigest()
|
|
130
|
+
file_name = f"{digest}.{extension}"
|
|
131
|
+
if file_name not in self._assets:
|
|
132
|
+
self._assets[file_name] = EpubAsset(
|
|
133
|
+
file_name=file_name,
|
|
134
|
+
media_type=_MEDIA_TYPES[extension],
|
|
135
|
+
data=normalized,
|
|
136
|
+
)
|
|
137
|
+
return f"../assets/{file_name}"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _prepare_epub_image(data: bytes, *, declared_extension: str | None) -> tuple[bytes, str]:
|
|
141
|
+
"""校验图片字节,并把非 PNG/JPEG/GIF 栅格统一转为 PNG。"""
|
|
142
|
+
if not isinstance(data, bytes) or not data:
|
|
143
|
+
raise ValueError("Image payload must contain bytes")
|
|
144
|
+
if len(data) > MAX_IMAGE_PAYLOAD_BYTES:
|
|
145
|
+
raise ValueError("Image payload exceeds its byte limit")
|
|
146
|
+
expected = normalize_image_extension(declared_extension or "") or None
|
|
147
|
+
if expected == "svg" or _SVG_START_RE.match(data[:4096]) is not None:
|
|
148
|
+
if expected not in {None, "svg"}:
|
|
149
|
+
raise ValueError("Image bytes do not match the declared format")
|
|
150
|
+
fallback, _, _ = extract_generated_svg_fallback(data)
|
|
151
|
+
return _prepare_epub_image(fallback, declared_extension="png")
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
with Image.open(BytesIO(data)) as image:
|
|
155
|
+
detected = normalize_image_extension(image.format or "")
|
|
156
|
+
if not detected:
|
|
157
|
+
raise ValueError("Unsupported image format")
|
|
158
|
+
validate_decoded_raster_size(*image.size)
|
|
159
|
+
image.load()
|
|
160
|
+
if expected is not None and expected != detected:
|
|
161
|
+
raise ValueError("Image bytes do not match the declared format")
|
|
162
|
+
if detected in _PASSTHROUGH_FORMATS:
|
|
163
|
+
return data, detected
|
|
164
|
+
has_alpha = "A" in image.getbands() or (image.mode == "P" and "transparency" in image.info)
|
|
165
|
+
converted = image.convert("RGBA" if has_alpha else "RGB")
|
|
166
|
+
output = BytesIO()
|
|
167
|
+
converted.save(output, format="PNG")
|
|
168
|
+
return output.getvalue(), "png"
|
|
169
|
+
except (Image.DecompressionBombError, UnidentifiedImageError, OSError, ValueError) as exc:
|
|
170
|
+
raise ValueError("Invalid or unsupported image payload") from exc
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
__all__ = ["EpubAsset", "EpubAssetRegistry"]
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"""EPUB 3.3 的元数据 XML、导航文档与确定性 OCF 打包。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import calendar
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from io import BytesIO
|
|
9
|
+
from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile, ZipInfo
|
|
10
|
+
|
|
11
|
+
from lxml import etree
|
|
12
|
+
|
|
13
|
+
from .assets import EpubAsset
|
|
14
|
+
|
|
15
|
+
_CONTAINER_NS = "urn:oasis:names:tc:opendocument:xmlns:container"
|
|
16
|
+
_DC_NS = "http://purl.org/dc/elements/1.1/"
|
|
17
|
+
_EPUB_NS = "http://www.idpf.org/2007/ops"
|
|
18
|
+
_OPF_NS = "http://www.idpf.org/2007/opf"
|
|
19
|
+
_XHTML_NS = "http://www.w3.org/1999/xhtml"
|
|
20
|
+
_XML_NS = "http://www.w3.org/XML/1998/namespace"
|
|
21
|
+
_EPUB_MIME = b"application/epub+zip"
|
|
22
|
+
_CONTENT_PATH = "EPUB/text/content.xhtml"
|
|
23
|
+
_STYLE_PATH = "EPUB/styles/docvortex.css"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True, slots=True)
|
|
27
|
+
class EpubMetadata:
|
|
28
|
+
"""保存 package document 所需的规范化书籍元数据。"""
|
|
29
|
+
|
|
30
|
+
title: str
|
|
31
|
+
authors: tuple[str, ...]
|
|
32
|
+
language: str
|
|
33
|
+
identifier: str
|
|
34
|
+
modified_at: datetime
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(slots=True)
|
|
38
|
+
class NavigationItem:
|
|
39
|
+
"""保存 EPUB toc nav 中一个可链接的层级条目。"""
|
|
40
|
+
|
|
41
|
+
title: str
|
|
42
|
+
href: str
|
|
43
|
+
children: list[NavigationItem] = field(default_factory=list)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def build_epub_package(
|
|
47
|
+
*,
|
|
48
|
+
metadata: EpubMetadata,
|
|
49
|
+
content_xhtml: bytes,
|
|
50
|
+
navigation: list[NavigationItem],
|
|
51
|
+
stylesheet: bytes,
|
|
52
|
+
assets: tuple[EpubAsset, ...],
|
|
53
|
+
has_mathml: bool,
|
|
54
|
+
) -> bytes:
|
|
55
|
+
"""在内存中按固定成员顺序构造完整 EPUB 3.3 容器。"""
|
|
56
|
+
container_xml = _build_container_xml()
|
|
57
|
+
navigation_xhtml = _build_navigation_xhtml(metadata, navigation)
|
|
58
|
+
package_document = _build_package_document(metadata, assets, has_mathml=has_mathml)
|
|
59
|
+
output = BytesIO()
|
|
60
|
+
with ZipFile(output, "w", compression=ZIP_DEFLATED, compresslevel=9) as archive:
|
|
61
|
+
_write_member(archive, "mimetype", _EPUB_MIME, metadata.modified_at, compression=ZIP_STORED)
|
|
62
|
+
_write_member(archive, "META-INF/container.xml", container_xml, metadata.modified_at)
|
|
63
|
+
_write_member(archive, "EPUB/package.opf", package_document, metadata.modified_at)
|
|
64
|
+
_write_member(archive, "EPUB/nav.xhtml", navigation_xhtml, metadata.modified_at)
|
|
65
|
+
_write_member(archive, _CONTENT_PATH, content_xhtml, metadata.modified_at)
|
|
66
|
+
_write_member(archive, _STYLE_PATH, stylesheet, metadata.modified_at)
|
|
67
|
+
for asset in assets:
|
|
68
|
+
_write_member(archive, f"EPUB/assets/{asset.file_name}", asset.data, metadata.modified_at)
|
|
69
|
+
return output.getvalue()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _build_container_xml() -> bytes:
|
|
73
|
+
"""生成指向唯一 OPF package document 的 container.xml。"""
|
|
74
|
+
root = etree.Element(f"{{{_CONTAINER_NS}}}container", nsmap={None: _CONTAINER_NS}, version="1.0")
|
|
75
|
+
rootfiles = etree.SubElement(root, f"{{{_CONTAINER_NS}}}rootfiles")
|
|
76
|
+
etree.SubElement(
|
|
77
|
+
rootfiles,
|
|
78
|
+
f"{{{_CONTAINER_NS}}}rootfile",
|
|
79
|
+
attrib={
|
|
80
|
+
"full-path": "EPUB/package.opf",
|
|
81
|
+
"media-type": "application/oebps-package+xml",
|
|
82
|
+
},
|
|
83
|
+
)
|
|
84
|
+
return _serialize_xml(root)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _build_package_document(metadata: EpubMetadata, assets: tuple[EpubAsset, ...], *, has_mathml: bool) -> bytes:
|
|
88
|
+
"""生成包含必需元数据、完整 manifest 与单正文 spine 的 OPF。"""
|
|
89
|
+
root = etree.Element(
|
|
90
|
+
f"{{{_OPF_NS}}}package",
|
|
91
|
+
nsmap={None: _OPF_NS, "dc": _DC_NS},
|
|
92
|
+
attrib={
|
|
93
|
+
"version": "3.0",
|
|
94
|
+
"unique-identifier": "pub-id",
|
|
95
|
+
f"{{{_XML_NS}}}lang": metadata.language,
|
|
96
|
+
},
|
|
97
|
+
)
|
|
98
|
+
metadata_element = etree.SubElement(root, f"{{{_OPF_NS}}}metadata")
|
|
99
|
+
identifier = etree.SubElement(metadata_element, f"{{{_DC_NS}}}identifier", id="pub-id")
|
|
100
|
+
identifier.text = metadata.identifier
|
|
101
|
+
title = etree.SubElement(metadata_element, f"{{{_DC_NS}}}title")
|
|
102
|
+
title.text = metadata.title
|
|
103
|
+
language = etree.SubElement(metadata_element, f"{{{_DC_NS}}}language")
|
|
104
|
+
language.text = metadata.language
|
|
105
|
+
for author in metadata.authors:
|
|
106
|
+
creator = etree.SubElement(metadata_element, f"{{{_DC_NS}}}creator")
|
|
107
|
+
creator.text = author
|
|
108
|
+
modified = etree.SubElement(metadata_element, f"{{{_OPF_NS}}}meta", property="dcterms:modified")
|
|
109
|
+
modified.text = metadata.modified_at.strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
110
|
+
|
|
111
|
+
manifest = etree.SubElement(root, f"{{{_OPF_NS}}}manifest")
|
|
112
|
+
etree.SubElement(
|
|
113
|
+
manifest,
|
|
114
|
+
f"{{{_OPF_NS}}}item",
|
|
115
|
+
id="nav",
|
|
116
|
+
href="nav.xhtml",
|
|
117
|
+
attrib={"media-type": "application/xhtml+xml", "properties": "nav"},
|
|
118
|
+
)
|
|
119
|
+
content_attributes = {
|
|
120
|
+
"id": "content",
|
|
121
|
+
"href": "text/content.xhtml",
|
|
122
|
+
"media-type": "application/xhtml+xml",
|
|
123
|
+
}
|
|
124
|
+
if has_mathml:
|
|
125
|
+
content_attributes["properties"] = "mathml"
|
|
126
|
+
etree.SubElement(manifest, f"{{{_OPF_NS}}}item", attrib=content_attributes)
|
|
127
|
+
etree.SubElement(
|
|
128
|
+
manifest,
|
|
129
|
+
f"{{{_OPF_NS}}}item",
|
|
130
|
+
id="style",
|
|
131
|
+
href="styles/docvortex.css",
|
|
132
|
+
attrib={"media-type": "text/css"},
|
|
133
|
+
)
|
|
134
|
+
for position, asset in enumerate(assets, start=1):
|
|
135
|
+
etree.SubElement(
|
|
136
|
+
manifest,
|
|
137
|
+
f"{{{_OPF_NS}}}item",
|
|
138
|
+
id=f"asset-{position}",
|
|
139
|
+
href=f"assets/{asset.file_name}",
|
|
140
|
+
attrib={"media-type": asset.media_type},
|
|
141
|
+
)
|
|
142
|
+
spine = etree.SubElement(root, f"{{{_OPF_NS}}}spine")
|
|
143
|
+
etree.SubElement(spine, f"{{{_OPF_NS}}}itemref", idref="content")
|
|
144
|
+
return _serialize_xml(root)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _build_navigation_xhtml(metadata: EpubMetadata, navigation: list[NavigationItem]) -> bytes:
|
|
148
|
+
"""生成恰含一个 toc nav 和一个 landmarks nav 的 EPUB 导航文档。"""
|
|
149
|
+
root = etree.Element(
|
|
150
|
+
f"{{{_XHTML_NS}}}html",
|
|
151
|
+
nsmap={None: _XHTML_NS, "epub": _EPUB_NS},
|
|
152
|
+
attrib={f"{{{_XML_NS}}}lang": metadata.language, "lang": metadata.language},
|
|
153
|
+
)
|
|
154
|
+
head = etree.SubElement(root, f"{{{_XHTML_NS}}}head")
|
|
155
|
+
etree.SubElement(head, f"{{{_XHTML_NS}}}meta", charset="utf-8")
|
|
156
|
+
title = etree.SubElement(head, f"{{{_XHTML_NS}}}title")
|
|
157
|
+
title.text = f"{metadata.title} — Table of Contents"
|
|
158
|
+
etree.SubElement(
|
|
159
|
+
head,
|
|
160
|
+
f"{{{_XHTML_NS}}}link",
|
|
161
|
+
rel="stylesheet",
|
|
162
|
+
href="styles/docvortex.css",
|
|
163
|
+
type="text/css",
|
|
164
|
+
)
|
|
165
|
+
body = etree.SubElement(root, f"{{{_XHTML_NS}}}body")
|
|
166
|
+
toc = etree.SubElement(
|
|
167
|
+
body,
|
|
168
|
+
f"{{{_XHTML_NS}}}nav",
|
|
169
|
+
id="toc",
|
|
170
|
+
role="doc-toc",
|
|
171
|
+
attrib={f"{{{_EPUB_NS}}}type": "toc"},
|
|
172
|
+
)
|
|
173
|
+
heading = etree.SubElement(toc, f"{{{_XHTML_NS}}}h1")
|
|
174
|
+
heading.text = "Table of Contents"
|
|
175
|
+
ordered = etree.SubElement(toc, f"{{{_XHTML_NS}}}ol")
|
|
176
|
+
for item in navigation:
|
|
177
|
+
_append_navigation_item(ordered, item)
|
|
178
|
+
|
|
179
|
+
landmarks = etree.SubElement(
|
|
180
|
+
body,
|
|
181
|
+
f"{{{_XHTML_NS}}}nav",
|
|
182
|
+
id="landmarks",
|
|
183
|
+
hidden="hidden",
|
|
184
|
+
attrib={f"{{{_EPUB_NS}}}type": "landmarks"},
|
|
185
|
+
)
|
|
186
|
+
landmarks_heading = etree.SubElement(landmarks, f"{{{_XHTML_NS}}}h2")
|
|
187
|
+
landmarks_heading.text = "Landmarks"
|
|
188
|
+
landmarks_list = etree.SubElement(landmarks, f"{{{_XHTML_NS}}}ol")
|
|
189
|
+
item = etree.SubElement(landmarks_list, f"{{{_XHTML_NS}}}li")
|
|
190
|
+
link = etree.SubElement(
|
|
191
|
+
item,
|
|
192
|
+
f"{{{_XHTML_NS}}}a",
|
|
193
|
+
href="text/content.xhtml#content-start",
|
|
194
|
+
attrib={f"{{{_EPUB_NS}}}type": "bodymatter"},
|
|
195
|
+
)
|
|
196
|
+
link.text = "Start of Content"
|
|
197
|
+
return _serialize_xml(root, doctype="<!DOCTYPE html>")
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _append_navigation_item(parent: etree._Element, item: NavigationItem) -> None:
|
|
201
|
+
"""递归把一个导航条目及其子项写入有序列表。"""
|
|
202
|
+
entry = etree.SubElement(parent, f"{{{_XHTML_NS}}}li")
|
|
203
|
+
link = etree.SubElement(entry, f"{{{_XHTML_NS}}}a", href=item.href)
|
|
204
|
+
link.text = item.title
|
|
205
|
+
if item.children:
|
|
206
|
+
nested = etree.SubElement(entry, f"{{{_XHTML_NS}}}ol")
|
|
207
|
+
for child in item.children:
|
|
208
|
+
_append_navigation_item(nested, child)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _serialize_xml(root: etree._Element, *, doctype: str | None = None) -> bytes:
|
|
212
|
+
"""以 UTF-8 XML 声明和稳定缩进序列化一个 EPUB XML 文档。"""
|
|
213
|
+
etree.indent(root, space=" ")
|
|
214
|
+
return etree.tostring(
|
|
215
|
+
root,
|
|
216
|
+
encoding="utf-8",
|
|
217
|
+
xml_declaration=True,
|
|
218
|
+
doctype=doctype,
|
|
219
|
+
pretty_print=True,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _write_member(
|
|
224
|
+
archive: ZipFile,
|
|
225
|
+
name: str,
|
|
226
|
+
data: bytes,
|
|
227
|
+
modified_at: datetime,
|
|
228
|
+
*,
|
|
229
|
+
compression: int = ZIP_DEFLATED,
|
|
230
|
+
) -> None:
|
|
231
|
+
"""用固定权限、无 extra 字段和规范时间写入一个 OCF ZIP 成员。"""
|
|
232
|
+
info = ZipInfo(name, date_time=_zip_datetime(modified_at))
|
|
233
|
+
info.compress_type = compression
|
|
234
|
+
info.create_system = 3
|
|
235
|
+
info.external_attr = 0o100644 << 16
|
|
236
|
+
info.extra = b""
|
|
237
|
+
info.comment = b""
|
|
238
|
+
archive.writestr(info, data)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _zip_datetime(modified_at: datetime) -> tuple[int, int, int, int, int, int]:
|
|
242
|
+
"""把 UTC 修改时间约束到 ZIP DOS 时间范围并截断到双秒。"""
|
|
243
|
+
year = min(max(modified_at.year, 1980), 2107)
|
|
244
|
+
day = min(modified_at.day, calendar.monthrange(year, modified_at.month)[1])
|
|
245
|
+
second = modified_at.second - modified_at.second % 2
|
|
246
|
+
return year, modified_at.month, day, modified_at.hour, modified_at.minute, second
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
__all__ = ["EpubMetadata", "NavigationItem", "build_epub_package"]
|