@@ -21,7 +21,7 @@ def __init__(self, status, type, message, metadata=None) -> None:
2121class ModernMT (object ):
2222 def __init__ (self , api_key , platform = "modernmt-python" , platform_version = "1.2.0" , api_client = None ) -> None :
2323 self .__batch_public_key = None
24- self .__batch_public_key_timestamp = 0
24+ self .__batch_public_key_timestamp_sec = 0
2525
2626 self .__base_url = "https://api.modernmt.com"
2727 self .__headers = {
@@ -121,17 +121,17 @@ def batch_translate(self, webhook, source, target, q, hints=None, context_vector
121121
122122 headers = None
123123 if options is not None and "idempotency_key" in options :
124- headers = { "x-idempotency-key" : options ["idempotency_key" ] }
124+ headers = {"x-idempotency-key" : options ["idempotency_key" ]}
125125
126126 res = self .__send ("post" , "/translate/batch" , data = data , headers = headers )
127127
128128 return res ["enqueued" ]
129129
130- def handle_callback (self , data , signature ):
130+ def handle_callback (self , body , signature ):
131131 if self .__batch_public_key is None :
132132 self .__refresh_public_key ()
133133
134- if time .time () - self .__batch_public_key_timestamp > 3600 :
134+ if time .time () - self .__batch_public_key_timestamp_sec > 3600 :
135135 # noinspection PyBroadException
136136 try :
137137 self .__refresh_public_key ()
@@ -140,22 +140,22 @@ def handle_callback(self, data, signature):
140140
141141 jwt .decode (signature , self .__batch_public_key , algorithms = ["RS256" ])
142142
143- if isinstance (data , str ):
144- data = json .loads (data )
143+ if isinstance (body , str ):
144+ body = json .loads (body )
145145
146- result = data ["result" ]
147- metadata = data .get ("metadata" , None )
146+ result = body ["result" ]
147+ metadata = body .get ("metadata" , None )
148148 error = result .get ("error" , None )
149149
150150 if error is not None :
151151 raise ModernMTException (result ["status" ], error ["type" ], error ["message" ], metadata )
152152
153- return BatchTranslation (data )
153+ return BatchTranslation (body )
154154
155155 def __refresh_public_key (self ):
156156 data = self .__send ("get" , "/translate/batch/key" )
157157 self .__batch_public_key = base64 .b64decode (data ["publicKey" ])
158- self .__batch_public_key_timestamp = time .time ()
158+ self .__batch_public_key_timestamp_sec = time .time ()
159159
160160 def get_context_vector (self , source , targets , text , hints = None , limit = None ):
161161 data = {"source" : source , "text" : text , "targets" : targets }
0 commit comments