1
1
import base64
2
2
from typing import Union
3
3
4
+ from regula .documentreader .webclient import ProcessResponse
5
+ from regula .documentreader .webclient .gen import ApiClient
4
6
from regula .documentreader .webclient .ext .models .recognition_response import RecognitionResponse
5
- from regula .documentreader .webclient .gen import ApiClient , Configuration
6
7
from regula .documentreader .webclient .gen .api import DefaultApi
8
+ from regula .documentreader .webclient .gen .configuration import Configuration
7
9
from regula .documentreader .webclient .gen .models import ProcessRequest
8
10
9
11
Base64String = str
@@ -13,13 +15,16 @@ class DocumentReaderApi(DefaultApi):
13
15
14
16
def __init__ (self , host = None , debug = False , verify_ssl = False , api_client = None ):
15
17
if api_client :
16
- super (). __init__ ( api_client )
18
+ self . api_client = api_client
17
19
else :
18
20
configuration = Configuration (host = host )
19
21
configuration .debug = debug
20
22
configuration .verify_ssl = verify_ssl
21
23
22
- super ().__init__ (ApiClient (configuration = configuration ))
24
+ self .api_client = ApiClient (configuration = configuration )
25
+
26
+ super ().__init__ (self .api_client )
27
+
23
28
self .__license = None
24
29
25
30
def __enter__ (self ):
@@ -42,3 +47,12 @@ def license(self, value: Union[Base64String, bytes]):
42
47
def process (self , process_request : ProcessRequest ) -> RecognitionResponse :
43
48
process_request .system_info .license = self .license
44
49
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