فهرست منبع

adding a try to avoid zlib.error when parsing a library which is not compressed

Léo Laffeach 2 سال پیش
والد
کامیت
87264cc1dc
1فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 5 1
      drawio2py/shapelib.py

+ 5 - 1
drawio2py/shapelib.py

@@ -6,6 +6,7 @@ import json
 import secrets
 import xml.etree.ElementTree as ET
 import copy
+import zlib
 
 from drawio2py.abstract_syntax import *
 from drawio2py.parser import Parser
@@ -19,7 +20,10 @@ def parse_library(path) -> Dict[str, Cell]:
     library = {}
     for el in elements:
         # Every element in the array has a "title" (shown to the user when hovering the shape) and "xml", which is actually Base64-encoded compressed URL-encoded XML (lol) (of an <mxgraphmodel>), which is the same format as what we encounter in a .drawio file:
-        mxgm = Parser.decode_and_deflate(el["xml"])
+        try:
+            mxgm = Parser.decode_and_deflate(el["xml"])
+        except zlib.error:
+            mxgm = ET.fromstring(el["xml"])
         # We create a dictionary mapping title to <mxgraphmodel>:
         shape_root = Parser.parse_mxgraphmodel(mxgm)