Skip to content

Commit a0eb5ab

Browse files
author
Release Manager
committed
sagemathgh-41041: better error message in magma_free when timeout fix sagemath#38430 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. URL: sagemath#41041 Reported by: Frédéric Chapoton Reviewer(s):
2 parents bbe8389 + d68e75f commit a0eb5ab

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/sage/interfaces/magma_free.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818

1919
class MagmaExpr(str):
20-
def __repr__(self):
20+
def __repr__(self) -> str:
2121
return str(self)
2222

2323

24-
def magma_free_eval(code, strip=True, columns=0):
24+
def magma_free_eval(code: str, strip=True, columns=0):
2525
"""
2626
Use the free online MAGMA calculator to evaluate the given
2727
input code and return the answer as a string.
@@ -30,6 +30,7 @@ def magma_free_eval(code, strip=True, columns=0):
3030
3131
The code must evaluate in at most 120 seconds
3232
and there is a limitation on the amount of RAM.
33+
Otherwise, some :exc:`TimeoutError` will be raised.
3334
3435
EXAMPLES::
3536
@@ -54,21 +55,18 @@ def magma_free_eval(code, strip=True, columns=0):
5455
results = response.read()
5556
conn.close()
5657

58+
if b"Timeout" in results:
59+
raise TimeoutError('timeout from the server')
60+
5761
xmlDoc = parseString(results)
58-
res = []
62+
res: list[str] = []
5963
resultsNodeList = xmlDoc.getElementsByTagName('results')
60-
if len(resultsNodeList) > 0:
64+
if resultsNodeList:
6165
resultsNode = resultsNodeList[0]
6266
lines = resultsNode.getElementsByTagName('line')
6367
for line in lines:
64-
for textNode in line.childNodes:
65-
res.append(textNode.data)
66-
res = "\n".join(res)
67-
68-
class MagmaExpr(str):
69-
def __repr__(self):
70-
return str(self)
71-
return MagmaExpr(res)
68+
res.extend(textNode.data for textNode in line.childNodes)
69+
return MagmaExpr("\n".join(res))
7270

7371

7472
class MagmaFree:

0 commit comments

Comments
 (0)