mumuki-python-runner 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/query_hook.rb +20 -2
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 455c69fffcdae300add9b25991d5f2c23faae08e2b436f4686f42a401f887c91
|
4
|
+
data.tar.gz: 36f51f7970e4a9cc2e967ad58e546f5ac814cd44c72c457c22311918c262b9a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe53ed3c6c32dad95b2e4550f5ff898294bb44dc7da169a2c14b554ad82e790a3f47e4f6cf7bc426dc4a3aa4943805762cac00bbb6761ebf8c77cc5a36872e1
|
7
|
+
data.tar.gz: 731beea5c08220b3eae104122d929476039e63f435825c6dd6b23fb60cf727187a4c2653f487311d758c6ab93b1ac84e50d4ab4b3da11f97566fefc72ce171e8
|
data/lib/query_hook.rb
CHANGED
@@ -7,21 +7,39 @@ class PythonQueryHook < Mumukit::Templates::FileHook
|
|
7
7
|
|
8
8
|
def compile_file_content(req)
|
9
9
|
<<python
|
10
|
-
import string
|
10
|
+
import string, sys, os
|
11
11
|
|
12
12
|
#{req.extra}
|
13
13
|
#{req.content}
|
14
|
+
sys.stdout = open(os.devnull, 'w')
|
15
|
+
#{compile_cookie(req.cookie)}
|
16
|
+
sys.stdout = sys.__stdout__
|
14
17
|
#{build_query req.query}
|
15
18
|
python
|
16
19
|
end
|
17
20
|
|
18
21
|
def build_query(query)
|
19
|
-
if query.match /print *(\(| )
|
22
|
+
if query.match /print *(\(| ).*|^[a-zA-Z_]\w*\s*=.*|^raise\b/
|
20
23
|
query
|
21
24
|
else
|
22
25
|
"print(string.Template(\"=> $result\").substitute(result = #{query}))"
|
23
26
|
end
|
24
27
|
end
|
28
|
+
|
29
|
+
def build_state(cookie)
|
30
|
+
(cookie||[]).map do |statement|
|
31
|
+
<<~python
|
32
|
+
try:
|
33
|
+
#{statement}
|
34
|
+
except:
|
35
|
+
pass
|
36
|
+
python
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def compile_cookie(cookie)
|
41
|
+
build_state(cookie).join("\n")
|
42
|
+
end
|
25
43
|
end
|
26
44
|
|
27
45
|
|
data/lib/version.rb
CHANGED