Skip to content

Commit 920b2b6

Browse files
committed
Change handle_callback to return data, metadata
1 parent bb12355 commit 920b2b6

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

src/modernmt/modernmt.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,15 @@ def handle_callback(self, body, signature):
150150
if error is not None:
151151
raise ModernMTException(result["status"], error["type"], error["message"], metadata)
152152

153-
return BatchTranslation(body)
153+
_data = result["data"]
154+
if not isinstance(_data, list):
155+
data = Translation(_data)
156+
else:
157+
data = []
158+
for el in _data:
159+
data.append(Translation(el))
160+
161+
return data, metadata
154162

155163
def __refresh_public_key(self):
156164
data = self.__send("get", "/translate/batch/key")
@@ -319,23 +327,6 @@ def __init__(self, data) -> None:
319327
])
320328

321329

322-
class BatchTranslation(_Model):
323-
def __init__(self, data) -> None:
324-
super().__init__({}, [])
325-
326-
_data = data["result"]["data"]
327-
328-
if not isinstance(_data, list):
329-
self.__dict__["data"] = Translation(_data)
330-
else:
331-
self.__dict__["data"] = []
332-
for el in _data:
333-
self.__dict__["data"].append(Translation(el))
334-
335-
if "metadata" in data:
336-
self.__dict__["metadata"] = data["metadata"]
337-
338-
339330
class Memory(_Model):
340331
def __init__(self, data) -> None:
341332
super().__init__(data, ["id", "name", "description", "creationDate"])

0 commit comments

Comments
 (0)