polish example file
-def get_dxf_doc_from_upload_data(dxf_uploaded_base64_data):
+# Copyright (c) 2020, Joseph Flack
+# License: MIT License
+from typing import TYPE_CHECKING, Optional
+import io
+import base64
+import ezdxf
+from ezdxf.filemanagement import dxf_stream_info
+
+if TYPE_CHECKING:
+ from ezdxf.eztypes import Drawing
+
+
+def get_dxf_doc_from_upload_data(data: bytes) -> Optional['Drawing']:
"""
- This function turns the dxf data provided by Dash Plotly upload component into an EZDXF doc
- Dash plotly upload compoment only provides base 64 encoded data.
- This returns an ezdxf doc object
+ This function turns the dxf data provided by Dash Plotly upload component into an `ezdxf` doc
+ Dash plotly upload component only provides base 64 encoded data.
+
+ Args:
+ data: DXF document uploaded as base64 encoded data
+
+ Returns:
+ DXF document as Drawing() object
+
"""
- if dxf_uploaded_base64_data is not None:
+ if data is None:
+ return None
+
# turn contents list into string. Contents is 64 encoded as per dash plotly
- contents = str(dxf_uploaded_base64_data)
+ contents = str(data)
# remove the first part of the decoded info Raw Content
# example: data:application/vnd.ms-excel;base64,ICAwU0VDVElPTiAgMkhFQURFUiAgOSRBQ0FEVkVSICAxQUMxMDI0ICA5JEFDQURNQUlOVFZFUiA3MDYgIDkkRFdHQ09ERVBBR0
content_type, content_string = contents.split(',')
