Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat: refactor legacy error handling and update module imports
myhloli4749bb655850
diff --git a/mineru/model/flash/office/doc/doc_converter.py b/mineru/model/flash/office/doc/doc_converter.pyindex ba97db0f..45942d17 100644--- a/mineru/model/flash/office/doc/doc_converter.py+++ b/mineru/model/flash/office/doc/doc_converter.py@@ -8,14 +8,15 @@ from html import escapeimport refrom typing import Any, BinaryIO, Iterable-from ..legacy import BoundedOleReader, LegacyOfficeEncryptedError+from ..errors import LegacyOfficeEncryptedErrorfrom ..image import serialize_office_image-from ..legacy.stream import read_stream_bytes_from_start+from ..legacy.ole import BoundedOleReader+from ..streams import read_stream_bytes_from_startfrom .....types import RAW_CAPTION, BlockTypefrom ..rich_text import OfficeRichTextSegment, build_rich_text_from_segmentsfrom .fib import parse_fib-from ..legacy.mtef import read_object_pool_equations+from ..equation.mtef import read_object_pool_equationsfrom ..xls.embedded_chart import extract_embedded_chart_htmlfrom .models import (DocCharStyle,diff --git a/mineru/model/flash/office/doc/fib.py b/mineru/model/flash/office/doc/fib.pyindex 9603f6da..8d22bbc5 100644--- a/mineru/model/flash/office/doc/fib.py+++ b/mineru/model/flash/office/doc/fib.py@@ -7,7 +7,7 @@ from __future__ import annotationsfrom dataclasses import dataclassimport struct-from ..legacy import LegacyOfficeMalformedError+from ..errors import LegacyOfficeMalformedErrorFIB_IDENT = 0xA5ECMIN_WORD97_NFIB = 0x00C1diff --git a/mineru/model/flash/office/doc/images.py b/mineru/model/flash/office/doc/images.pyindex 39830237..e7c69afe 100644--- a/mineru/model/flash/office/doc/images.py+++ b/mineru/model/flash/office/doc/images.py@@ -9,9 +9,9 @@ import hashlibfrom loguru import logger-from ..legacy import LegacyOfficeResourceLimitError+from ..errors import LegacyOfficeResourceLimitErrorfrom ..legacy.binary import bounded_slice, get_u16, get_u32-from ..legacy.limits import MAX_ASSET_TOTAL_BYTES+from ..limits import MAX_ASSET_TOTAL_BYTESfrom ..legacy.officeart import (OfficeImagePayload,decode_bstore,@@ -19,7 +19,7 @@ from ..legacy.officeart import (first_blip,record_at,)-from ..image_equation import (+from ..equation.image import (OfficeImageEquationDecoder,)diff --git a/mineru/model/flash/office/doc/parser.py b/mineru/model/flash/office/doc/parser.pyindex b6f330b1..785d2d9d 100644--- a/mineru/model/flash/office/doc/parser.py+++ b/mineru/model/flash/office/doc/parser.py@@ -7,7 +7,7 @@ from __future__ import annotationsfrom dataclasses import dataclass, fieldfrom loguru import logger-from ..legacy import LegacyOfficeMalformedError+from ..errors import LegacyOfficeMalformedErrorfrom ..legacy.binary import bounded_slicefrom .bookmarks import parse_bookmarksdiff --git a/mineru/model/flash/office/doc/pieces.py b/mineru/model/flash/office/doc/pieces.pyindex c04090a2..ee84134a 100644--- a/mineru/model/flash/office/doc/pieces.py+++ b/mineru/model/flash/office/doc/pieces.py@@ -8,7 +8,7 @@ from bisect import bisect_leftfrom dataclasses import dataclassimport struct-from ..legacy import LegacyOfficeMalformedError+from ..errors import LegacyOfficeMalformedErrorfrom ..legacy.binary import bounded_slice, get_u16, get_u32from .records import DocBudgetdiff --git a/mineru/model/flash/office/doc/records.py b/mineru/model/flash/office/doc/records.pyindex fa226931..42faf66a 100644--- a/mineru/model/flash/office/doc/records.py+++ b/mineru/model/flash/office/doc/records.py@@ -7,8 +7,8 @@ from __future__ import annotationsfrom dataclasses import dataclassimport struct-from ..legacy import LegacyOfficeResourceLimitError-from ..legacy.limits import MAX_RECORDS+from ..errors import LegacyOfficeResourceLimitError+from ..limits import MAX_RECORDS@dataclass(slots=True)diff --git a/mineru/model/flash/office/docx/docx_converter.py b/mineru/model/flash/office/docx/docx_converter.pyindex 9deccc5d..a3694c58 100644--- a/mineru/model/flash/office/docx/docx_converter.py+++ b/mineru/model/flash/office/docx/docx_converter.py@@ -18,22 +18,22 @@ from mammoth.conversion import convert_document_element_to_htmlfrom mammoth.docx import body_xmlfrom pydantic import AnyUrl-from ..chart import extract_chart_html_from_ooxml+from ..ooxml_chart import extract_chart_html_from_ooxmlfrom ..image import (serialize_office_image,)-from ..ooxml_equation import (+from ..equation.ooxml import (OoxmlEquationDecoder,is_mathtype_equation_prog_id,)-from ..image_equation import (+from ..equation.image import (OfficeImageEquationDecoder,)from .....types import RAW_CAPTIONfrom .equationxml import DocxEquationXmlDecoderfrom .package_normalizer import normalize_docx_package-from ..math.omml import oMath2Latex-from .tools.office_xml import read_str+from ..equation.omml import oMath2Latex+from .office_xml import read_strfrom .....types import BlockTypefrom .formatting_types import Formatting, Scriptfrom ..rich_text import (diff --git a/mineru/model/flash/office/docx/equationxml.py b/mineru/model/flash/office/docx/equationxml.pyindex dc67bd84..9ae862b7 100644--- a/mineru/model/flash/office/docx/equationxml.py+++ b/mineru/model/flash/office/docx/equationxml.py@@ -9,11 +9,11 @@ import hashlibfrom lxml import etree # type: ignore[reportAttributeAccessIssue]-from ..math.omml import oMath2Latex-from ..legacy.errors import (+from ..equation.omml import oMath2Latex+from ..errors import (LegacyOfficeResourceLimitError,)-from ..legacy.limits import (+from ..limits import (MAX_ASSET_TOTAL_BYTES,MAX_ENTRY_BYTES,)diff --git a/mineru/model/flash/office/docx/tools/office_xml.py b/mineru/model/flash/office/docx/office_xml.pysimilarity index 96%rename from mineru/model/flash/office/docx/tools/office_xml.pyrename to mineru/model/flash/office/docx/office_xml.pyindex f16e71dc..7ef02d91 100644--- a/mineru/model/flash/office/docx/tools/office_xml.py+++ b/mineru/model/flash/office/docx/office_xml.py@@ -1,4 +1,6 @@# Copyright (c) Opendatalab. All rights reserved.+"""DOCX Mammoth 兼容层使用的 Office XML 解析辅助函数。"""+import xml.dom.minidomfrom mammoth.docx.xmlparser import XmlText, XmlElementdiff --git a/mineru/model/flash/office/docx/tools/__init__.py b/mineru/model/flash/office/equation/__init__.pysimilarity index 53%rename from mineru/model/flash/office/docx/tools/__init__.pyrename to mineru/model/flash/office/equation/__init__.pyindex 818730ae..23a977a8 100644--- a/mineru/model/flash/office/docx/tools/__init__.py+++ b/mineru/model/flash/office/equation/__init__.py@@ -1,3 +1,4 @@# Copyright (c) Opendatalab. All rights reserved.+"""Office 公式格式与嵌入载体的内部解析实现。"""__all__: list[str] = []diff --git a/mineru/model/flash/office/image_equation.py b/mineru/model/flash/office/equation/image.pysimilarity index 99%rename from mineru/model/flash/office/image_equation.pyrename to mineru/model/flash/office/equation/image.pyindex ae008852..a5535572 100644--- a/mineru/model/flash/office/image_equation.py+++ b/mineru/model/flash/office/equation/image.py@@ -11,15 +11,15 @@ import structfrom loguru import logger-from .legacy.errors import (+from ..errors import (LegacyOfficeResourceLimitError,)-from .legacy.limits import (+from ..limits import (MAX_ASSET_TOTAL_BYTES,MAX_ENTRY_BYTES,MAX_PICTURE_RECORDS,)-from .legacy.mtef import decode_mtef+from .mtef import decode_mtef_PLACEABLE_WMF_MAGIC = b"\xd7\xcd\xc6\x9a"_META_ESCAPE = 0x0626diff --git a/mineru/model/flash/office/math/latex_dict.py b/mineru/model/flash/office/equation/latex_dict.pysimilarity index 100%rename from mineru/model/flash/office/math/latex_dict.pyrename to mineru/model/flash/office/equation/latex_dict.pydiff --git a/mineru/model/flash/office/legacy/mtef.py b/mineru/model/flash/office/equation/mtef.pysimilarity index 99%rename from mineru/model/flash/office/legacy/mtef.pyrename to mineru/model/flash/office/equation/mtef.pyindex 570eee8d..854932d5 100644--- a/mineru/model/flash/office/legacy/mtef.py+++ b/mineru/model/flash/office/equation/mtef.py@@ -10,9 +10,9 @@ import structfrom loguru import logger-from .errors import LegacyOfficeResourceLimitError-from .limits import MAX_RECORD_DEPTH, MAX_RECORDS-from .ole import BoundedOleReader+from ..errors import LegacyOfficeResourceLimitError+from ..limits import MAX_RECORD_DEPTH, MAX_RECORDS+from ..legacy.ole import BoundedOleReader_OBJECT_POOL_EQUATION_RE = re.compile(r"^ObjectPool/_([0-9]+)/Equation Native$",diff --git a/mineru/model/flash/office/legacy/mtef_v5.py b/mineru/model/flash/office/equation/mtef_v5.pysimilarity index 99%rename from mineru/model/flash/office/legacy/mtef_v5.pyrename to mineru/model/flash/office/equation/mtef_v5.pyindex 10f4f2bb..d44cbad3 100644--- a/mineru/model/flash/office/legacy/mtef_v5.py+++ b/mineru/model/flash/office/equation/mtef_v5.py@@ -7,8 +7,8 @@ from __future__ import annotationsfrom dataclasses import dataclassimport struct-from .errors import LegacyOfficeResourceLimitError-from .limits import MAX_RECORD_DEPTH, MAX_RECORDS+from ..errors import LegacyOfficeResourceLimitError+from ..limits import MAX_RECORD_DEPTH, MAX_RECORDSfrom .mtef import _MtefError, _Node, _render_node_OPT_NUDGE = 0x08diff --git a/mineru/model/flash/office/math/omml.py b/mineru/model/flash/office/equation/omml.pysimilarity index 100%rename from mineru/model/flash/office/math/omml.pyrename to mineru/model/flash/office/equation/omml.pydiff --git a/mineru/model/flash/office/ooxml_equation.py b/mineru/model/flash/office/equation/ooxml.pysimilarity index 94%rename from mineru/model/flash/office/ooxml_equation.pyrename to mineru/model/flash/office/equation/ooxml.pyindex 26fcc9c4..c95e84df 100644--- a/mineru/model/flash/office/ooxml_equation.py+++ b/mineru/model/flash/office/equation/ooxml.py@@ -7,12 +7,12 @@ from __future__ import annotationsfrom dataclasses import dataclass, fieldimport hashlib-from .legacy.errors import LegacyOfficeResourceLimitError-from .legacy.limits import (+from ..errors import LegacyOfficeResourceLimitError+from ..limits import (MAX_ASSET_TOTAL_BYTES,MAX_ENTRY_BYTES,)-from .legacy.mtef import decode_equation_object+from .mtef import decode_equation_objectCFB_MAGIC = b"\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1"EQUATION_PROG_ID = "equation"diff --git a/mineru/model/flash/office/legacy/errors.py b/mineru/model/flash/office/errors.pysimilarity index 90%rename from mineru/model/flash/office/legacy/errors.pyrename to mineru/model/flash/office/errors.pyindex fb462b4f..6532db86 100644--- a/mineru/model/flash/office/legacy/errors.py+++ b/mineru/model/flash/office/errors.py@@ -1,6 +1,6 @@# Copyright (c) Opendatalab. All rights reserved.-"""旧版 Office 解析过程中可稳定识别的错误类型。"""+"""Flash Office 二进制、嵌入对象与 RTF 解析共享的稳定错误类型。"""from __future__ import annotations@@ -33,4 +33,3 @@ class LegacyOfficeResourceLimitError(LegacyOfficeError):"""输入超过固定安全限制。"""code = "resource_limit"-diff --git a/mineru/model/flash/office/legacy/__init__.py b/mineru/model/flash/office/legacy/__init__.pyindex 8368f720..e97beed2 100644--- a/mineru/model/flash/office/legacy/__init__.py+++ b/mineru/model/flash/office/legacy/__init__.py@@ -1,19 +1,5 @@# Copyright (c) Opendatalab. All rights reserved.-"""旧版 Office 二进制格式共享基础设施。"""+"""旧版 Office OLE、OfficeArt 与二进制读取实现。"""-from .errors import (- LegacyOfficeEncryptedError,- LegacyOfficeMalformedError,- LegacyOfficeMissingPartError,- LegacyOfficeResourceLimitError,-)-from .ole import BoundedOleReader--__all__ = [- "BoundedOleReader",- "LegacyOfficeEncryptedError",- "LegacyOfficeMalformedError",- "LegacyOfficeMissingPartError",- "LegacyOfficeResourceLimitError",-]+__all__: list[str] = []diff --git a/mineru/model/flash/office/legacy/officeart.py b/mineru/model/flash/office/legacy/officeart.pyindex 17dc93a3..c0aeed31 100644--- a/mineru/model/flash/office/legacy/officeart.py+++ b/mineru/model/flash/office/legacy/officeart.py@@ -12,8 +12,8 @@ import zlibfrom loguru import loggerfrom ..image import ensure_bmp_header-from .errors import LegacyOfficeResourceLimitError-from .limits import (+from ..errors import LegacyOfficeResourceLimitError+from ..limits import (MAX_ASSET_TOTAL_BYTES,MAX_ENTRY_BYTES,MAX_PICTURE_RECORDS,diff --git a/mineru/model/flash/office/legacy/ole.py b/mineru/model/flash/office/legacy/ole.pyindex e64a71d3..dc46c047 100644--- a/mineru/model/flash/office/legacy/ole.py+++ b/mineru/model/flash/office/legacy/ole.py@@ -9,12 +9,12 @@ from typing import Anyimport olefile # type: ignore[reportMissingModuleSource]-from .errors import (+from ..errors import (LegacyOfficeMalformedError,LegacyOfficeMissingPartError,LegacyOfficeResourceLimitError,)-from .limits import MAX_ENTRY_BYTES, MAX_TOTAL_BYTES+from ..limits import MAX_ENTRY_BYTES, MAX_TOTAL_BYTESclass BoundedOleReader:diff --git a/mineru/model/flash/office/legacy/limits.py b/mineru/model/flash/office/limits.pysimilarity index 81%rename from mineru/model/flash/office/legacy/limits.pyrename to mineru/model/flash/office/limits.pyindex eead9877..b345adbe 100644--- a/mineru/model/flash/office/legacy/limits.py+++ b/mineru/model/flash/office/limits.py@@ -1,6 +1,6 @@# Copyright (c) Opendatalab. All rights reserved.-"""旧版 Office 解析使用的固定安全限制。"""+"""Flash Office 二进制、嵌入对象与 RTF 解析共享的固定安全限制。"""from typing import Finaldiff --git a/mineru/model/flash/office/math/__init__.py b/mineru/model/flash/office/math/__init__.pydeleted file mode 100644index 73641dfa..00000000--- a/mineru/model/flash/office/math/__init__.py+++ /dev/null@@ -1,4 +0,0 @@-# Copyright (c) Opendatalab. All rights reserved.-"""Office Math 内部转换实现。"""--__all__: list[str] = []diff --git a/mineru/model/flash/office/chart.py b/mineru/model/flash/office/ooxml_chart.pysimilarity index 100%rename from mineru/model/flash/office/chart.pyrename to mineru/model/flash/office/ooxml_chart.pydiff --git a/mineru/model/flash/office/ppt/parser.py b/mineru/model/flash/office/ppt/parser.pyindex 3c0e1705..e2cc5f19 100644--- a/mineru/model/flash/office/ppt/parser.py+++ b/mineru/model/flash/office/ppt/parser.py@@ -13,28 +13,28 @@ import zlibfrom loguru import logger-from ..legacy import (- BoundedOleReader,+from ..errors import (LegacyOfficeEncryptedError,LegacyOfficeMalformedError,LegacyOfficeResourceLimitError,)from ..legacy.binary import get_i16, get_u16, get_u32-from ..legacy.limits import (+from ..limits import (MAX_ASSET_TOTAL_BYTES,MAX_ENTRY_BYTES,MAX_GRID_SLOTS,MAX_PICTURE_RECORDS,MAX_USER_EDIT_CHAIN,)-from ..legacy.mtef import decode_equation_object+from ..equation.mtef import decode_equation_object+from ..legacy.ole import BoundedOleReaderfrom ..legacy.officeart import (OfficeArtRecord,OfficeImagePayload,decode_blip as decode_officeart_blip,)from ..image import serialize_office_image-from ..image_equation import (+from ..equation.image import (OfficeImageEquationDecoder,)from ..xls.embedded_chart import extract_embedded_chart_html_from_storagediff --git a/mineru/model/flash/office/ppt/ppt_converter.py b/mineru/model/flash/office/ppt/ppt_converter.pyindex 60f327e4..64fe4f1b 100644--- a/mineru/model/flash/office/ppt/ppt_converter.py+++ b/mineru/model/flash/office/ppt/ppt_converter.py@@ -7,9 +7,9 @@ from __future__ import annotationsfrom html import escapefrom typing import Any, BinaryIO-from ..legacy import BoundedOleReader+from ..legacy.ole import BoundedOleReaderfrom ..._shared.xycut import sort_entries-from ..legacy.stream import read_stream_bytes_from_start+from ..streams import read_stream_bytes_from_startfrom .....types import BlockTypefrom ..rich_text import OfficeRichTextSegment, build_rich_text_from_segmentsdiff --git a/mineru/model/flash/office/ppt/records.py b/mineru/model/flash/office/ppt/records.pyindex 04aa3a1f..35d29257 100644--- a/mineru/model/flash/office/ppt/records.py+++ b/mineru/model/flash/office/ppt/records.py@@ -8,11 +8,11 @@ from dataclasses import dataclassimport structfrom typing import Iterator-from ..legacy.errors import (+from ..errors import (LegacyOfficeMalformedError,LegacyOfficeResourceLimitError,)-from ..legacy.limits import MAX_RECORD_DEPTH, MAX_RECORDS+from ..limits import MAX_RECORD_DEPTH, MAX_RECORDSCONTAINER_VERSION = 0xFROUNDTRIP_OPAQUE_MIN = 1053diff --git a/mineru/model/flash/office/pptx/pptx_converter.py b/mineru/model/flash/office/pptx/pptx_converter.pyindex 917325f6..4ef021d8 100644--- a/mineru/model/flash/office/pptx/pptx_converter.py+++ b/mineru/model/flash/office/pptx/pptx_converter.py@@ -12,17 +12,17 @@ from pptx import Presentation, presentationfrom pptx.enum.shapes import MSO_SHAPE_TYPE, PP_PLACEHOLDERfrom pptx.oxml.text import CT_TextLineBreak-from ..chart import extract_chart_html_from_ooxml+from ..ooxml_chart import extract_chart_html_from_ooxmlfrom ..image import PIL_IMAGE_LOAD_ERRORS, is_vector_image, serialize_vector_image_with_placeholder-from ..image_equation import (+from ..equation.image import (OfficeImageEquationDecoder,)-from ..ooxml_equation import (+from ..equation.ooxml import (OoxmlEquationDecoder,is_mathtype_equation_prog_id,)-from ..math.omml import oMath2Latex-from ..legacy.stream import read_stream_bytes_from_start, rewind_stream+from ..equation.omml import oMath2Latex+from ..streams import read_stream_bytes_from_start, rewind_streamfrom .package_normalizer import normalize_pptx_packagefrom ..._shared.xycut import sort_entriesfrom .....types import BlockTypediff --git a/mineru/model/flash/office/rtf/converter.py b/mineru/model/flash/office/rtf/converter.pyindex deec46c4..e0b10530 100644--- a/mineru/model/flash/office/rtf/converter.py+++ b/mineru/model/flash/office/rtf/converter.py@@ -14,7 +14,7 @@ from ..image import (is_vector_image_part,serialize_office_image,)-from ..image_equation import OfficeImageEquationDecoder+from ..equation.image import OfficeImageEquationDecoderfrom ..rich_text import OfficeRichTextSegment, build_rich_text_from_segmentsfrom .models import (RtfAnchor,diff --git a/mineru/model/flash/office/rtf/lexer.py b/mineru/model/flash/office/rtf/lexer.pyindex 8146bab3..e87e5333 100644--- a/mineru/model/flash/office/rtf/lexer.py+++ b/mineru/model/flash/office/rtf/lexer.py@@ -6,8 +6,8 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom typing import Iterator, TypeAlias, Union-from ..legacy import LegacyOfficeMalformedError, LegacyOfficeResourceLimitError-from ..legacy.limits import MAX_RECORDS+from ..errors import LegacyOfficeMalformedError, LegacyOfficeResourceLimitError+from ..limits import MAX_RECORDSMAX_RTF_GROUP_DEPTH = 256diff --git a/mineru/model/flash/office/rtf/math.py b/mineru/model/flash/office/rtf/math.pyindex 6fc28aa2..ea875aeb 100644--- a/mineru/model/flash/office/rtf/math.py+++ b/mineru/model/flash/office/rtf/math.py@@ -8,7 +8,7 @@ from dataclasses import dataclass, fieldfrom lxml import etree # type: ignore[reportAttributeAccessIssue]from loguru import logger-from ..math.omml import oMath2Latex+from ..equation.omml import oMath2Latexfrom .lexer import RtfClose, RtfControlWord, RtfHexByte, RtfLexer, RtfOpen, RtfTextBytes_MATH_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math"diff --git a/mineru/model/flash/office/rtf/parser.py b/mineru/model/flash/office/rtf/parser.pyindex 4e06d5e0..657e177e 100644--- a/mineru/model/flash/office/rtf/parser.py+++ b/mineru/model/flash/office/rtf/parser.py@@ -12,8 +12,8 @@ from urllib.parse import urlsplitfrom loguru import loggerfrom .....filetypes import rtf_header_offset-from ..legacy import LegacyOfficeMalformedError, LegacyOfficeResourceLimitError-from ..legacy.limits import MAX_ASSET_TOTAL_BYTES, MAX_ENTRY_BYTES, MAX_GRID_SLOTS+from ..errors import LegacyOfficeMalformedError, LegacyOfficeResourceLimitError+from ..limits import MAX_ASSET_TOTAL_BYTES, MAX_ENTRY_BYTES, MAX_GRID_SLOTSfrom .lexer import (RtfBinary,RtfClose,diff --git a/mineru/model/flash/office/legacy/stream.py b/mineru/model/flash/office/streams.pysimilarity index 88%rename from mineru/model/flash/office/legacy/stream.pyrename to mineru/model/flash/office/streams.pyindex 51431c12..0a6b5171 100644--- a/mineru/model/flash/office/legacy/stream.py+++ b/mineru/model/flash/office/streams.py@@ -1,4 +1,6 @@# Copyright (c) Opendatalab. All rights reserved.+"""Flash Office 转换器复用的调用方二进制流读取能力。"""+from typing import BinaryIOdiff --git a/mineru/model/flash/office/xls/embedded_chart.py b/mineru/model/flash/office/xls/embedded_chart.pyindex 032917ce..c7c53b59 100644--- a/mineru/model/flash/office/xls/embedded_chart.py+++ b/mineru/model/flash/office/xls/embedded_chart.py@@ -9,13 +9,13 @@ import structfrom loguru import logger-from ..legacy import BoundedOleReader+from ..legacy.ole import BoundedOleReaderfrom ..legacy.binary import get_f64, get_u16-from ..legacy.errors import (+from ..errors import (LegacyOfficeMalformedError,LegacyOfficeResourceLimitError,)-from ..legacy.limits import MAX_GRID_SLOTS+from ..limits import MAX_GRID_SLOTSfrom .models import XlsCell, XlsRichText, XlsSheet, XlsWorkbookfrom .number_format import builtin_number_format, format_numberfrom .parser import parse_xls_workbookdiff --git a/mineru/model/flash/office/xls/parser.py b/mineru/model/flash/office/xls/parser.pyindex 2bde9cd2..3bbdf2e8 100644--- a/mineru/model/flash/office/xls/parser.py+++ b/mineru/model/flash/office/xls/parser.py@@ -11,7 +11,7 @@ import uuidfrom loguru import logger-from ..legacy.errors import (+from ..errors import (LegacyOfficeEncryptedError,LegacyOfficeMalformedError,)@@ -23,7 +23,7 @@ from ..legacy.officeart import (extract_excel_shapes,)from ..image import serialize_office_image-from ..image_equation import (+from ..equation.image import (OfficeImageEquationDecoder,)diff --git a/mineru/model/flash/office/xls/records.py b/mineru/model/flash/office/xls/records.pyindex 9fa544db..38aa3287 100644--- a/mineru/model/flash/office/xls/records.py+++ b/mineru/model/flash/office/xls/records.py@@ -10,8 +10,8 @@ from typing import Iteratorfrom loguru import logger-from ..legacy.errors import LegacyOfficeResourceLimitError-from ..legacy.limits import MAX_RECORDS+from ..errors import LegacyOfficeResourceLimitError+from ..limits import MAX_RECORDSBOF = 0x0809EOF = 0x000Adiff --git a/mineru/model/flash/office/xls/xls_converter.py b/mineru/model/flash/office/xls/xls_converter.pyindex a8ac827c..4f19b18f 100644--- a/mineru/model/flash/office/xls/xls_converter.py+++ b/mineru/model/flash/office/xls/xls_converter.py@@ -14,14 +14,14 @@ from openpyxl.cell.rich_text import CellRichText, TextBlock # type: ignore[repofrom openpyxl.cell.text import InlineFont # type: ignore[reportMissingModuleSource]from openpyxl.worksheet.worksheet import Worksheet # type: ignore[reportMissingModuleSource]-from ..legacy import BoundedOleReader, LegacyOfficeEncryptedError-from ..legacy.errors import LegacyOfficeResourceLimitError-from ..legacy.limits import MAX_GRID_SLOTS-from ..legacy.mtef import decode_equation_native+from ..errors import LegacyOfficeEncryptedError, LegacyOfficeResourceLimitError+from ..limits import MAX_GRID_SLOTS+from ..equation.mtef import decode_equation_native+from ..legacy.ole import BoundedOleReaderfrom ..spreadsheet.html import render_spreadsheet_tablefrom ..spreadsheet.models import AnchoredBlock, ExcelTable, FormulaMap, SheetImagefrom ..spreadsheet.projector import SpreadsheetProjector-from ..legacy.stream import read_stream_bytes_from_start+from ..streams import read_stream_bytes_from_startfrom .....types import BlockTypefrom .models import XlsChart, XlsChartSheet, XlsRichText, XlsSheet, XlsWorkbookdiff --git a/mineru/model/flash/office/xlsx/ooxml_ole.py b/mineru/model/flash/office/xlsx/ooxml_ole.pyindex cf49743a..c4e5bd8e 100644--- a/mineru/model/flash/office/xlsx/ooxml_ole.py+++ b/mineru/model/flash/office/xlsx/ooxml_ole.py@@ -12,13 +12,13 @@ import xml.etree.ElementTree as ETfrom loguru import logger-from ..legacy.errors import LegacyOfficeResourceLimitError-from ..legacy.limits import MAX_ENTRY_BYTES+from ..errors import LegacyOfficeResourceLimitError+from ..limits import MAX_ENTRY_BYTESfrom ..image import serialize_office_image-from ..image_equation import (+from ..equation.image import (OfficeImageEquationDecoder,)-from ..ooxml_equation import (+from ..equation.ooxml import (OoxmlEquationDecoder,is_mathtype_equation_prog_id,)diff --git a/mineru/model/flash/office/xlsx/xlsx_converter.py b/mineru/model/flash/office/xlsx/xlsx_converter.pyindex 30febbaf..1ecc7f28 100644--- a/mineru/model/flash/office/xlsx/xlsx_converter.py+++ b/mineru/model/flash/office/xlsx/xlsx_converter.py@@ -16,14 +16,14 @@ from openpyxl.worksheet.worksheet import Worksheetfrom PIL import Imagefrom ..image import is_vector_image, serialize_vector_image_with_placeholderfrom ..image import serialize_office_image-from ..image_equation import (+from ..equation.image import (OfficeImageEquationDecoder,)-from ..ooxml_equation import OoxmlEquationDecoder-from ..legacy.errors import LegacyOfficeResourceLimitError-from ..legacy.limits import MAX_ENTRY_BYTES-from ..math.omml import oMath2Latex-from ..legacy.stream import read_stream_bytes_from_start, rewind_stream+from ..equation.ooxml import OoxmlEquationDecoder+from ..errors import LegacyOfficeResourceLimitError+from ..limits import MAX_ENTRY_BYTES+from ..equation.omml import oMath2Latex+from ..streams import read_stream_bytes_from_start, rewind_streamfrom ..spreadsheet.html import EQUATION_BOOKENDS, render_spreadsheet_tablefrom ..spreadsheet.models import AnchoredBlock, FormulaMap, SheetImagefrom ..spreadsheet.projector import SpreadsheetProjectordiff --git a/tests/unittest/test_backend_architecture.py b/tests/unittest/test_backend_architecture.pyindex 88746244..96f04e42 100644--- a/tests/unittest/test_backend_architecture.py+++ b/tests/unittest/test_backend_architecture.py@@ -52,7 +52,17 @@ _REMOVED_INTERNAL_MODULES = ("mineru.model.model_types","mineru.model.flash.model","mineru.model.flash.native_pdf",+ "mineru.model.flash.office.chart",+ "mineru.model.flash.office.docx.tools","mineru.model.flash.office.docx.tools.math",+ "mineru.model.flash.office.image_equation",+ "mineru.model.flash.office.legacy.errors",+ "mineru.model.flash.office.legacy.limits",+ "mineru.model.flash.office.legacy.mtef",+ "mineru.model.flash.office.legacy.mtef_v5",+ "mineru.model.flash.office.legacy.stream",+ "mineru.model.flash.office.math",+ "mineru.model.flash.office.ooxml_equation","mineru.model.utils","mineru.render.writer","mineru.render._internal.common.inline",@@ -236,6 +246,28 @@ def test_flash_spreadsheet_dependencies_are_one_way() -> None:assert not {path: imports for path, imports in spreadsheet_offenders.items() if imports}+def test_flash_equation_and_legacy_dependencies_are_one_way() -> None:+ """守卫公式层不反向引用格式实现,legacy 层也不重新承载公式解析。"""+ format_prefixes = tuple(+ f"mineru.model.flash.office.{name}"+ for name in ("doc", "docx", "odf", "ppt", "pptx", "rtf", "spreadsheet", "xls", "xlsx")+ )+ equation_offenders = {+ str(path.relative_to(_PROJECT_ROOT)): sorted(+ module for module in _resolved_imports(path) if module.startswith(format_prefixes)+ )+ for path in (_PROJECT_ROOT / "mineru/model/flash/office/equation").rglob("*.py")+ }+ legacy_offenders = {+ str(path.relative_to(_PROJECT_ROOT)): sorted(+ module for module in _resolved_imports(path) if module.startswith("mineru.model.flash.office.equation")+ )+ for path in (_PROJECT_ROOT / "mineru/model/flash/office/legacy").rglob("*.py")+ }+ assert not {path: imports for path, imports in equation_offenders.items() if imports}+ assert not {path: imports for path, imports in legacy_offenders.items() if imports}++def test_package_initializers_define_explicit_all() -> None:"""守卫目标目录下每个包入口都显式声明 __all__。"""offenders = [diff --git a/tests/unittest/test_flash_docx_equationxml.py b/tests/unittest/test_flash_docx_equationxml.pyindex 67399501..c3a3528c 100644--- a/tests/unittest/test_flash_docx_equationxml.py+++ b/tests/unittest/test_flash_docx_equationxml.py@@ -11,7 +11,7 @@ from mineru.backend.analyze import aio_doc_analyze, doc_analyzefrom mineru.model.flash import DocxModelfrom mineru.model.flash.office.docx.docx_converter import DocxConverterfrom mineru.model.flash.office.docx.equationxml import DocxEquationXmlDecoder-from mineru.model.flash.office.legacy.errors import (+from mineru.model.flash.office.errors import (LegacyOfficeResourceLimitError,)from mineru.render._internal.docx.math import latex_to_ommldiff --git a/tests/unittest/test_flash_image_mtef.py b/tests/unittest/test_flash_image_mtef.pyindex e8d22170..07c15cb6 100644--- a/tests/unittest/test_flash_image_mtef.py+++ b/tests/unittest/test_flash_image_mtef.py@@ -2,9 +2,9 @@ from __future__ import annotationsimport pytest-from mineru.model.flash.office.legacy.errors import LegacyOfficeResourceLimitError-from mineru.model.flash.office import image_equation as image_equation_module-from mineru.model.flash.office.image_equation import (+from mineru.model.flash.office.errors import LegacyOfficeResourceLimitError+from mineru.model.flash.office.equation import image as image_equation_module+from mineru.model.flash.office.equation.image import (OfficeImageEquationDecoder,decode_image_embedded_equation,)diff --git a/tests/unittest/test_flash_legacy_doc.py b/tests/unittest/test_flash_legacy_doc.pyindex 9d090b3e..efa114ff 100644--- a/tests/unittest/test_flash_legacy_doc.py+++ b/tests/unittest/test_flash_legacy_doc.py@@ -16,7 +16,7 @@ from mineru.model.flash.office.doc.models import DocCharStyle, DocTableCellfrom mineru.model.flash.office.doc.parser import _RawTableRow, _materialize_table_rowsfrom mineru.model.flash.office.doc.records import DocBudgetfrom mineru.model.flash.office.doc.sprm import apply_character_sprms-from mineru.model.flash.office.legacy import (+from mineru.model.flash.office.errors import (LegacyOfficeEncryptedError,LegacyOfficeMalformedError,LegacyOfficeMissingPartError,diff --git a/tests/unittest/test_flash_legacy_doc_mtef.py b/tests/unittest/test_flash_legacy_doc_mtef.pyindex c037d680..c7836155 100644--- a/tests/unittest/test_flash_legacy_doc_mtef.py+++ b/tests/unittest/test_flash_legacy_doc_mtef.py@@ -7,7 +7,7 @@ import pytestfrom mineru.backend.analyze import aio_doc_analyze, doc_analyzefrom mineru.model.flash import DocModel-from mineru.model.flash.office.legacy.mtef import (+from mineru.model.flash.office.equation.mtef import (decode_equation_native,decode_equation_object,decode_mtef_v3,diff --git a/tests/unittest/test_flash_legacy_ppt.py b/tests/unittest/test_flash_legacy_ppt.pyindex 5fd9de7d..aa70e8d0 100644--- a/tests/unittest/test_flash_legacy_ppt.py+++ b/tests/unittest/test_flash_legacy_ppt.py@@ -10,7 +10,7 @@ import pytestfrom mineru.backend.analyze import aio_doc_analyze, doc_analyzefrom mineru.model.flash import PptModel-from mineru.model.flash.office.legacy import LegacyOfficeEncryptedError, LegacyOfficeResourceLimitError+from mineru.model.flash.office.errors import LegacyOfficeEncryptedError, LegacyOfficeResourceLimitErrorfrom mineru.model.flash.office.ppt import parser as ppt_parserfrom mineru.model.flash.office.ppt.models import PptPresentation, PptSlidefrom mineru.model.flash.office.ppt.ppt_converter import PptConverterdiff --git a/tests/unittest/test_flash_legacy_xls.py b/tests/unittest/test_flash_legacy_xls.pyindex d141d684..e27925e8 100644--- a/tests/unittest/test_flash_legacy_xls.py+++ b/tests/unittest/test_flash_legacy_xls.py@@ -10,12 +10,12 @@ import pytestfrom mineru.backend.analyze import aio_doc_analyze, doc_analyzefrom mineru.model.flash import XlsModel-from mineru.model.flash.office.legacy import (+from mineru.model.flash.office.errors import (LegacyOfficeEncryptedError,LegacyOfficeMissingPartError,LegacyOfficeResourceLimitError,)-from mineru.model.flash.office.legacy.limits import MAX_RECORDS+from mineru.model.flash.office.limits import MAX_RECORDSfrom mineru.model.flash.office.xls import xls_converter as xls_converter_modulefrom mineru.model.flash.office.xls import parser as xls_parserfrom mineru.model.flash.office.xls.number_format import format_number, format_textdiff --git a/tests/unittest/test_flash_legacy_xls_ppt_mtef.py b/tests/unittest/test_flash_legacy_xls_ppt_mtef.pyindex 07e15fa7..04ea929a 100644--- a/tests/unittest/test_flash_legacy_xls_ppt_mtef.py+++ b/tests/unittest/test_flash_legacy_xls_ppt_mtef.py@@ -8,8 +8,8 @@ import pytestfrom mineru.backend.analyze import aio_doc_analyze, doc_analyzefrom mineru.model.flash import PptModel, XlsModel-from mineru.model.flash.office.legacy import LegacyOfficeResourceLimitError-from mineru.model.flash.office.legacy.limits import MAX_ENTRY_BYTES+from mineru.model.flash.office.errors import LegacyOfficeResourceLimitError+from mineru.model.flash.office.limits import MAX_ENTRY_BYTESfrom mineru.types import BlockType, MiddleJson, ModelJsonfrom _legacy_ppt_test_utils import build_equation_pptdiff --git a/tests/unittest/test_flash_mtef_v5.py b/tests/unittest/test_flash_mtef_v5.pyindex ace841a3..b52198b8 100644--- a/tests/unittest/test_flash_mtef_v5.py+++ b/tests/unittest/test_flash_mtef_v5.py@@ -4,10 +4,10 @@ import structimport pytest-from mineru.model.flash.office.legacy import mtef_v5 as mtef_v5_module-from mineru.model.flash.office.legacy import mtef as mtef_module-from mineru.model.flash.office.legacy.errors import LegacyOfficeResourceLimitError-from mineru.model.flash.office.legacy.mtef import (+from mineru.model.flash.office.equation import mtef_v5 as mtef_v5_module+from mineru.model.flash.office.equation import mtef as mtef_module+from mineru.model.flash.office.errors import LegacyOfficeResourceLimitError+from mineru.model.flash.office.equation.mtef import (decode_equation_native,decode_equation_object,decode_mtef,diff --git a/tests/unittest/test_flash_ooxml_mtef.py b/tests/unittest/test_flash_ooxml_mtef.pyindex 3734b0e2..2d8067a6 100644--- a/tests/unittest/test_flash_ooxml_mtef.py+++ b/tests/unittest/test_flash_ooxml_mtef.py@@ -11,9 +11,9 @@ import pytestfrom mineru.backend.analyze import aio_doc_analyze, doc_analyzefrom mineru.model.flash import DocxModel, PptxModel, XlsxModelfrom mineru.model.flash.office.docx.docx_converter import DocxConverter-from mineru.model.flash.office.legacy import LegacyOfficeResourceLimitError-from mineru.model.flash.office.legacy.limits import MAX_ASSET_TOTAL_BYTES-from mineru.model.flash.office.ooxml_equation import (+from mineru.model.flash.office.errors import LegacyOfficeResourceLimitError+from mineru.model.flash.office.limits import MAX_ASSET_TOTAL_BYTES+from mineru.model.flash.office.equation.ooxml import (OoxmlEquationDecoder,is_mathtype_equation_prog_id,)diff --git a/tests/unittest/test_flash_rtf.py b/tests/unittest/test_flash_rtf.pyindex 99ea8fdb..a0936f54 100644--- a/tests/unittest/test_flash_rtf.py+++ b/tests/unittest/test_flash_rtf.py@@ -15,7 +15,7 @@ from mineru.doclib.core.fts import FTSManagerfrom mineru.doclib.services.parse_svc import ParseServicefrom mineru.errors import InvalidRequestErrorfrom mineru.model.flash import RtfModel-from mineru.model.flash.office.legacy import (+from mineru.model.flash.office.errors import (LegacyOfficeMalformedError,LegacyOfficeResourceLimitError,)