2019-10-21 20:07:17 +00:00
|
|
|
import pytio
|
|
|
|
import http3
|
|
|
|
import gzip
|
|
|
|
import io
|
|
|
|
|
|
|
|
tio = pytio.Tio()
|
|
|
|
|
|
|
|
def languages():
|
|
|
|
return tio.query_languages()
|
|
|
|
|
|
|
|
aliases = {
|
2020-05-12 16:08:03 +00:00
|
|
|
"python": "python3",
|
|
|
|
"javascript": "javascript-node"
|
2019-10-21 20:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client = http3.AsyncClient()
|
|
|
|
|
|
|
|
async def run(lang, code):
|
2020-04-18 12:14:31 +00:00
|
|
|
real_lang = aliases.get(lang, lang)
|
|
|
|
req = pytio.TioRequest(real_lang, code)
|
2019-10-21 20:07:17 +00:00
|
|
|
res = await client.post("https://tio.run/cgi-bin/run/api/", data=req.as_deflated_bytes(), timeout=65)
|
|
|
|
content = res.content.decode("UTF-8")
|
|
|
|
split = list(filter(lambda x: x != "\n" and x != "", content.split(content[:16])))
|
|
|
|
if len(split) == 1:
|
2020-04-18 12:14:31 +00:00
|
|
|
return False, real_lang, split[0], None
|
2019-10-21 20:07:17 +00:00
|
|
|
else:
|
2020-05-12 16:08:03 +00:00
|
|
|
return True, real_lang, split[0], split[1]
|