1+ from typing import Optional
12import struct
23import zlib
34import sys
1112_PNG_SIGNATURE = b"\x89 PNG\r \n \x1a \n "
1213
1314
14- def _extract_from_png (data : bytes ) -> str | None :
15+ def _extract_from_png (data : bytes ) -> Optional [ str ] :
1516 #Return the GraphML string embedded in a PNG file, or None
1617 if data [:8 ] != _PNG_SIGNATURE :
1718 return None
@@ -87,7 +88,7 @@ def _extract_from_png(data: bytes) -> str | None:
8788_JPEG_SOI = b"\xff \xd8 "
8889
8990
90- def _extract_from_jpeg (data : bytes ) -> str | None :
91+ def _extract_from_jpeg (data : bytes ) -> Optional [ str ] :
9192 #Return the GraphML string embedded in a JPEG file, or None.
9293 if data [:2 ] != _JPEG_SOI :
9394 return None
@@ -119,7 +120,7 @@ def _extract_from_jpeg(data: bytes) -> str | None:
119120# ---------------------------------------------------------------------------
120121
121122
122- def extract_graphml (image_path : str ) -> str | None :
123+ def extract_graphml (image_path : str ) -> Optional [ str ] :
123124 try :
124125 with open (image_path , "rb" ) as fh :
125126 data = fh .read ()
@@ -141,7 +142,7 @@ def extract_graphml(image_path: str) -> str | None:
141142 return None
142143
143144
144- def extract_graphml_to_file (image_path : str , output_path : str | None = None ) -> str | None :
145+ def extract_graphml_to_file (image_path : str , output_path : Optional [ str ] = None ) -> Optional [ str ] :
145146 graphml = extract_graphml (image_path )
146147 if graphml is None :
147148 print (
0 commit comments