add monkey patch for docx parse error

This commit is contained in:
Windfarer
2026-04-01 10:42:23 +08:00
committed by lyingbug
parent 6eafde98a3
commit 6058f1cbe0
+22
View File
@@ -11,6 +11,28 @@ from io import BytesIO
from multiprocessing import Manager from multiprocessing import Manager
from typing import Any, Dict, List, Optional, Tuple from typing import Any, Dict, List, Optional, Tuple
from docx.opc.pkgreader import _SerializedRelationships, _SerializedRelationship
from docx.opc.oxml import parse_xml
def load_from_xml_v2(baseURI, rels_item_xml):
"""
Return |_SerializedRelationships| instance loaded with the
relationships contained in *rels_item_xml*. Returns an empty
collection if *rels_item_xml* is |None|.
"""
srels = _SerializedRelationships()
if rels_item_xml is not None:
rels_elm = parse_xml(rels_item_xml)
for rel_elm in rels_elm.Relationship_lst:
if rel_elm.target_ref in ('../NULL', 'NULL'):
continue
srels._srels.append(_SerializedRelationship(baseURI, rel_elm))
return srels
_SerializedRelationships.load_from_xml = load_from_xml_v2
from docx import Document from docx import Document
from docx.image.exceptions import ( from docx.image.exceptions import (
InvalidImageStreamError, InvalidImageStreamError,