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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/query_hook.rb +20 -2
  3. data/lib/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8f4a945f696d9aca5747019985522cdac67e46bb03f57471891d402c459595a
4
- data.tar.gz: 413a86b6b88bffeb22f6026ba3376955258ad0fc7e09d9c911edbc742f9a5182
3
+ metadata.gz: 455c69fffcdae300add9b25991d5f2c23faae08e2b436f4686f42a401f887c91
4
+ data.tar.gz: 36f51f7970e4a9cc2e967ad58e546f5ac814cd44c72c457c22311918c262b9a6
5
5
  SHA512:
6
- metadata.gz: '0139e1e2abf5a0ed8b0a54a533c4121c3aebf3196fd541caa95b019e0c2c49dc7b40dc30068c95eda03d8191a497a08955da6f301d71fbe67137d9bb03b4fc29'
7
- data.tar.gz: df340771674007222789bd111831bdf26b6d217e241e1a76a27bc70681a61c6429ff826a188dd19394746203f0903d6100d49756a67c6f05d647f84e80f7d4cf
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
@@ -1,3 +1,3 @@
1
1
  module PythonVersionHook
2
- VERSION = '1.2.2'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-python-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli