Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

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.py
index 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 escape
import re
from typing import Any, BinaryIO, Iterable
-from ..legacy import BoundedOleReader, LegacyOfficeEncryptedError
+from ..errors import LegacyOfficeEncryptedError
from ..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_start
from .....types import RAW_CAPTION, BlockType
from ..rich_text import OfficeRichTextSegment, build_rich_text_from_segments
from .fib import parse_fib
-from ..legacy.mtef import read_object_pool_equations
+from ..equation.mtef import read_object_pool_equations
from ..xls.embedded_chart import extract_embedded_chart_html
from .models import (
DocCharStyle,
diff --git a/mineru/model/flash/office/doc/fib.py b/mineru/model/flash/office/doc/fib.py
index 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 annotations
from dataclasses import dataclass
import struct
-from ..legacy import LegacyOfficeMalformedError
+from ..errors import LegacyOfficeMalformedError
FIB_IDENT = 0xA5EC
MIN_WORD97_NFIB = 0x00C1
diff --git a/mineru/model/flash/office/doc/images.py b/mineru/model/flash/office/doc/images.py
index 39830237..e7c69afe 100644
--- a/mineru/model/flash/office/doc/images.py
+++ b/mineru/model/flash/office/doc/images.py
@@ -9,9 +9,9 @@ import hashlib
from loguru import logger
-from ..legacy import LegacyOfficeResourceLimitError
+from ..errors import LegacyOfficeResourceLimitError
from ..legacy.binary import bounded_slice, get_u16, get_u32
-from ..legacy.limits import MAX_ASSET_TOTAL_BYTES
+from ..limits import MAX_ASSET_TOTAL_BYTES
from ..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.py
index 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 annotations
from dataclasses import dataclass, field
from loguru import logger
-from ..legacy import LegacyOfficeMalformedError
+from ..errors import LegacyOfficeMalformedError
from ..legacy.binary import bounded_slice
from .bookmarks import parse_bookmarks
diff --git a/mineru/model/flash/office/doc/pieces.py b/mineru/model/flash/office/doc/pieces.py
index 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_left
from dataclasses import dataclass
import struct
-from ..legacy import LegacyOfficeMalformedError
+from ..errors import LegacyOfficeMalformedError
from ..legacy.binary import bounded_slice, get_u16, get_u32
from .records import DocBudget
diff --git a/mineru/model/flash/office/doc/records.py b/mineru/model/flash/office/doc/records.py
index 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 annotations
from dataclasses import dataclass
import 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.py
index 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_html
from mammoth.docx import body_xml
from pydantic import AnyUrl
-from ..chart import extract_chart_html_from_ooxml
+from ..ooxml_chart import extract_chart_html_from_ooxml
from ..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_CAPTION
from .equationxml import DocxEquationXmlDecoder
from .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_str
from .....types import BlockType
from .formatting_types import Formatting, Script
from ..rich_text import (
diff --git a/mineru/model/flash/office/docx/equationxml.py b/mineru/model/flash/office/docx/equationxml.py
index dc67bd84..9ae862b7 100644
--- a/mineru/model/flash/office/docx/equationxml.py
+++ b/mineru/model/flash/office/docx/equationxml.py
@@ -9,11 +9,11 @@ import hashlib
from 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.py
similarity index 96%
rename from mineru/model/flash/office/docx/tools/office_xml.py
rename to mineru/model/flash/office/docx/office_xml.py
index 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.minidom
from mammoth.docx.xmlparser import XmlText, XmlElement
diff --git a/mineru/model/flash/office/docx/tools/__init__.py b/mineru/model/flash/office/equation/__init__.py
similarity index 53%
rename from mineru/model/flash/office/docx/tools/__init__.py
rename to mineru/model/flash/office/equation/__init__.py
index 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.py
similarity index 99%
rename from mineru/model/flash/office/image_equation.py
rename to mineru/model/flash/office/equation/image.py
index ae008852..a5535572 100644
--- a/mineru/model/flash/office/image_equation.py
+++ b/mineru/model/flash/office/equation/image.py
@@ -11,15 +11,15 @@ import struct
from 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 = 0x0626
diff --git a/mineru/model/flash/office/math/latex_dict.py b/mineru/model/flash/office/equation/latex_dict.py
similarity index 100%
rename from mineru/model/flash/office/math/latex_dict.py
rename to mineru/model/flash/office/equation/latex_dict.py
diff --git a/mineru/model/flash/office/legacy/mtef.py b/mineru/model/flash/office/equation/mtef.py
similarity index 99%
rename from mineru/model/flash/office/legacy/mtef.py
rename to mineru/model/flash/office/equation/mtef.py
index 570eee8d..854932d5 100644
--- a/mineru/model/flash/office/legacy/mtef.py
+++ b/mineru/model/flash/office/equation/mtef.py
@@ -10,9 +10,9 @@ import struct
from 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.py
similarity index 99%
rename from mineru/model/flash/office/legacy/mtef_v5.py
rename to mineru/model/flash/office/equation/mtef_v5.py
index 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 annotations
from dataclasses import dataclass
import struct
-from .errors import LegacyOfficeResourceLimitError
-from .limits import MAX_RECORD_DEPTH, MAX_RECORDS
+from ..errors import LegacyOfficeResourceLimitError
+from ..limits import MAX_RECORD_DEPTH, MAX_RECORDS
from .mtef import _MtefError, _Node, _render_node
_OPT_NUDGE = 0x08
diff --git a/mineru/model/flash/office/math/omml.py b/mineru/model/flash/office/equation/omml.py
similarity index 100%
rename from mineru/model/flash/office/math/omml.py
rename to mineru/model/flash/office/equation/omml.py
diff --git a/mineru/model/flash/office/ooxml_equation.py b/mineru/model/flash/office/equation/ooxml.py
similarity index 94%
rename from mineru/model/flash/office/ooxml_equation.py
rename to mineru/model/flash/office/equation/ooxml.py
index 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 annotations
from dataclasses import dataclass, field
import 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_object
CFB_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.py
similarity index 90%
rename from mineru/model/flash/office/legacy/errors.py
rename to mineru/model/flash/office/errors.py
index 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__.py
index 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.py
index 17dc93a3..c0aeed31 100644
--- a/mineru/model/flash/office/legacy/officeart.py
+++ b/mineru/model/flash/office/legacy/officeart.py
@@ -12,8 +12,8 @@ import zlib
from loguru import logger
from ..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.py
index 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 Any
import 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_BYTES
class BoundedOleReader:
diff --git a/mineru/model/flash/office/legacy/limits.py b/mineru/model/flash/office/limits.py
similarity index 81%
rename from mineru/model/flash/office/legacy/limits.py
rename to mineru/model/flash/office/limits.py
index 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 Final
diff --git a/mineru/model/flash/office/math/__init__.py b/mineru/model/flash/office/math/__init__.py
deleted file mode 100644
index 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.py
similarity index 100%
rename from mineru/model/flash/office/chart.py
rename to mineru/model/flash/office/ooxml_chart.py
diff --git a/mineru/model/flash/office/ppt/parser.py b/mineru/model/flash/office/ppt/parser.py
index 3c0e1705..e2cc5f19 100644
--- a/mineru/model/flash/office/ppt/parser.py
+++ b/mineru/model/flash/office/ppt/parser.py
@@ -13,28 +13,28 @@ import zlib
from 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 BoundedOleReader
from ..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_storage
diff --git a/mineru/model/flash/office/ppt/ppt_converter.py b/mineru/model/flash/office/ppt/ppt_converter.py
index 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 annotations
from html import escape
from typing import Any, BinaryIO
-from ..legacy import BoundedOleReader
+from ..legacy.ole import BoundedOleReader
from ..._shared.xycut import sort_entries
-from ..legacy.stream import read_stream_bytes_from_start
+from ..streams import read_stream_bytes_from_start
from .....types import BlockType
from ..rich_text import OfficeRichTextSegment, build_rich_text_from_segments
diff --git a/mineru/model/flash/office/ppt/records.py b/mineru/model/flash/office/ppt/records.py
index 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 dataclass
import struct
from 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_RECORDS
CONTAINER_VERSION = 0xF
ROUNDTRIP_OPAQUE_MIN = 1053
diff --git a/mineru/model/flash/office/pptx/pptx_converter.py b/mineru/model/flash/office/pptx/pptx_converter.py
index 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, presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE, PP_PLACEHOLDER
from pptx.oxml.text import CT_TextLineBreak
-from ..chart import extract_chart_html_from_ooxml
+from ..ooxml_chart import extract_chart_html_from_ooxml
from ..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_stream
from .package_normalizer import normalize_pptx_package
from ..._shared.xycut import sort_entries
from .....types import BlockType
diff --git a/mineru/model/flash/office/rtf/converter.py b/mineru/model/flash/office/rtf/converter.py
index 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 OfficeImageEquationDecoder
from ..rich_text import OfficeRichTextSegment, build_rich_text_from_segments
from .models import (
RtfAnchor,
diff --git a/mineru/model/flash/office/rtf/lexer.py b/mineru/model/flash/office/rtf/lexer.py
index 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 annotations
from dataclasses import dataclass
from 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_RECORDS
MAX_RTF_GROUP_DEPTH = 256
diff --git a/mineru/model/flash/office/rtf/math.py b/mineru/model/flash/office/rtf/math.py
index 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, field
from lxml import etree # type: ignore[reportAttributeAccessIssue]
from loguru import logger
-from ..math.omml import oMath2Latex
+from ..equation.omml import oMath2Latex
from .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.py
index 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 urlsplit
from loguru import logger
from .....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_SLOTS
from .lexer import (
RtfBinary,
RtfClose,
diff --git a/mineru/model/flash/office/legacy/stream.py b/mineru/model/flash/office/streams.py
similarity index 88%
rename from mineru/model/flash/office/legacy/stream.py
rename to mineru/model/flash/office/streams.py
index 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 BinaryIO
diff --git a/mineru/model/flash/office/xls/embedded_chart.py b/mineru/model/flash/office/xls/embedded_chart.py
index 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 struct
from loguru import logger
-from ..legacy import BoundedOleReader
+from ..legacy.ole import BoundedOleReader
from ..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_SLOTS
from .models import XlsCell, XlsRichText, XlsSheet, XlsWorkbook
from .number_format import builtin_number_format, format_number
from .parser import parse_xls_workbook
diff --git a/mineru/model/flash/office/xls/parser.py b/mineru/model/flash/office/xls/parser.py
index 2bde9cd2..3bbdf2e8 100644
--- a/mineru/model/flash/office/xls/parser.py
+++ b/mineru/model/flash/office/xls/parser.py
@@ -11,7 +11,7 @@ import uuid
from 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.py
index 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 Iterator
from loguru import logger
-from ..legacy.errors import LegacyOfficeResourceLimitError
-from ..legacy.limits import MAX_RECORDS
+from ..errors import LegacyOfficeResourceLimitError
+from ..limits import MAX_RECORDS
BOF = 0x0809
EOF = 0x000A
diff --git a/mineru/model/flash/office/xls/xls_converter.py b/mineru/model/flash/office/xls/xls_converter.py
index 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[repo
from 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 BoundedOleReader
from ..spreadsheet.html import render_spreadsheet_table
from ..spreadsheet.models import AnchoredBlock, ExcelTable, FormulaMap, SheetImage
from ..spreadsheet.projector import SpreadsheetProjector
-from ..legacy.stream import read_stream_bytes_from_start
+from ..streams import read_stream_bytes_from_start
from .....types import BlockType
from .models import XlsChart, XlsChartSheet, XlsRichText, XlsSheet, XlsWorkbook
diff --git a/mineru/model/flash/office/xlsx/ooxml_ole.py b/mineru/model/flash/office/xlsx/ooxml_ole.py
index 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 ET
from loguru import logger
-from ..legacy.errors import LegacyOfficeResourceLimitError
-from ..legacy.limits import MAX_ENTRY_BYTES
+from ..errors import LegacyOfficeResourceLimitError
+from ..limits import MAX_ENTRY_BYTES
from ..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.py
index 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 Worksheet
from PIL import Image
from ..image import is_vector_image, serialize_vector_image_with_placeholder
from ..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_stream
from ..spreadsheet.html import EQUATION_BOOKENDS, render_spreadsheet_table
from ..spreadsheet.models import AnchoredBlock, FormulaMap, SheetImage
from ..spreadsheet.projector import SpreadsheetProjector
diff --git a/tests/unittest/test_backend_architecture.py b/tests/unittest/test_backend_architecture.py
index 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.py
index 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_analyze
from mineru.model.flash import DocxModel
from mineru.model.flash.office.docx.docx_converter import DocxConverter
from 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_omml
diff --git a/tests/unittest/test_flash_image_mtef.py b/tests/unittest/test_flash_image_mtef.py
index 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 annotations
import 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.py
index 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, DocTableCell
from mineru.model.flash.office.doc.parser import _RawTableRow, _materialize_table_rows
from mineru.model.flash.office.doc.records import DocBudget
from 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.py
index 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 pytest
from mineru.backend.analyze import aio_doc_analyze, doc_analyze
from 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.py
index 5fd9de7d..aa70e8d0 100644
--- a/tests/unittest/test_flash_legacy_ppt.py
+++ b/tests/unittest/test_flash_legacy_ppt.py
@@ -10,7 +10,7 @@ import pytest
from mineru.backend.analyze import aio_doc_analyze, doc_analyze
from mineru.model.flash import PptModel
-from mineru.model.flash.office.legacy import LegacyOfficeEncryptedError, LegacyOfficeResourceLimitError
+from mineru.model.flash.office.errors import LegacyOfficeEncryptedError, LegacyOfficeResourceLimitError
from mineru.model.flash.office.ppt import parser as ppt_parser
from mineru.model.flash.office.ppt.models import PptPresentation, PptSlide
from mineru.model.flash.office.ppt.ppt_converter import PptConverter
diff --git a/tests/unittest/test_flash_legacy_xls.py b/tests/unittest/test_flash_legacy_xls.py
index d141d684..e27925e8 100644
--- a/tests/unittest/test_flash_legacy_xls.py
+++ b/tests/unittest/test_flash_legacy_xls.py
@@ -10,12 +10,12 @@ import pytest
from mineru.backend.analyze import aio_doc_analyze, doc_analyze
from 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_RECORDS
from mineru.model.flash.office.xls import xls_converter as xls_converter_module
from mineru.model.flash.office.xls import parser as xls_parser
from mineru.model.flash.office.xls.number_format import format_number, format_text
diff --git a/tests/unittest/test_flash_legacy_xls_ppt_mtef.py b/tests/unittest/test_flash_legacy_xls_ppt_mtef.py
index 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 pytest
from mineru.backend.analyze import aio_doc_analyze, doc_analyze
from 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_BYTES
from mineru.types import BlockType, MiddleJson, ModelJson
from _legacy_ppt_test_utils import build_equation_ppt
diff --git a/tests/unittest/test_flash_mtef_v5.py b/tests/unittest/test_flash_mtef_v5.py
index ace841a3..b52198b8 100644
--- a/tests/unittest/test_flash_mtef_v5.py
+++ b/tests/unittest/test_flash_mtef_v5.py
@@ -4,10 +4,10 @@ import struct
import 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.py
index 3734b0e2..2d8067a6 100644
--- a/tests/unittest/test_flash_ooxml_mtef.py
+++ b/tests/unittest/test_flash_ooxml_mtef.py
@@ -11,9 +11,9 @@ import pytest
from mineru.backend.analyze import aio_doc_analyze, doc_analyze
from mineru.model.flash import DocxModel, PptxModel, XlsxModel
from 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.py
index 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 FTSManager
from mineru.doclib.services.parse_svc import ParseService
from mineru.errors import InvalidRequestError
from mineru.model.flash import RtfModel
-from mineru.model.flash.office.legacy import (
+from mineru.model.flash.office.errors import (
LegacyOfficeMalformedError,
LegacyOfficeResourceLimitError,
)