11import base64
22from typing import Union
33
4+ from regula .documentreader .webclient import ProcessResponse
5+ from regula .documentreader .webclient .gen import ApiClient
46from regula .documentreader .webclient .ext .models .recognition_response import RecognitionResponse
5- from regula .documentreader .webclient .gen import ApiClient , Configuration
67from regula .documentreader .webclient .gen .api import DefaultApi
8+ from regula .documentreader .webclient .gen .configuration import Configuration
79from regula .documentreader .webclient .gen .models import ProcessRequest
810
911Base64String = str
@@ -13,13 +15,16 @@ class DocumentReaderApi(DefaultApi):
1315
1416 def __init__ (self , host = None , debug = False , verify_ssl = False , api_client = None ):
1517 if api_client :
16- super (). __init__ ( api_client )
18+ self . api_client = api_client
1719 else :
1820 configuration = Configuration (host = host )
1921 configuration .debug = debug
2022 configuration .verify_ssl = verify_ssl
2123
22- super ().__init__ (ApiClient (configuration = configuration ))
24+ self .api_client = ApiClient (configuration = configuration )
25+
26+ super ().__init__ (self .api_client )
27+
2328 self .__license = None
2429
2530 def __enter__ (self ):
@@ -42,3 +47,12 @@ def license(self, value: Union[Base64String, bytes]):
4247 def process (self , process_request : ProcessRequest ) -> RecognitionResponse :
4348 process_request .system_info .license = self .license
4449 return RecognitionResponse (self .api_process (process_request ))
50+
51+ def deserialize_to_recognition_response (self , content : Union [bytes , bytearray , str ]) -> RecognitionResponse :
52+ response = self .__to_response_object (content )
53+ response = self .api_client .deserialize (response , ProcessResponse )
54+ return RecognitionResponse (response )
55+
56+ @staticmethod
57+ def __to_response_object (content : Union [bytes , bytearray , str ]):
58+ return type (ProcessResponse .__name__ , (object ,), {"data" : content })()
0 commit comments