Class: BasePythonQueryHook
  
  
  
  
  
    - Inherits:
- 
      Mumukit::Templates::FileHook
      
        
          - Object
- Mumukit::Templates::FileHook
- BasePythonQueryHook
 show all
    - Defined in:
- lib/base/query_hook.rb
 
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
    Instance Method Details
    
      
  
  
    #command_line(filename)  ⇒ Object 
  
  
  
  
    | 
5
6
7 | # File 'lib/base/query_hook.rb', line 5
def command_line(filename)
  "python #{filename} 2>&1"
end | 
 
    
      
  
  
    #compile_cookie(cookie)  ⇒ Object 
  
  
  
  
    | 
38
39
40 | # File 'lib/base/query_hook.rb', line 38
def compile_cookie(cookie)
  compile_state(cookie).join("\n")
end | 
 
    
      
  
  
    #compile_file_content(req)  ⇒ Object 
  
  
  
  
    | 
9
10
11 | # File 'lib/base/query_hook.rb', line 9
def compile_file_content(req)
  "#{(req)}\n#{compile_query(req.query)}"
end | 
 
    
      
  
  
    | 
13
14
15
16
17
18
19
20
21
22
23
24
25 | # File 'lib/base/query_hook.rb', line 13
def (req)
  <<python
# -*- coding: UTF-8 -*-
import string, sys, os
from datetime import datetime, date
#{req.}
#{req.content}
sys.stdout = open(os.devnull, 'w')
#{compile_cookie(req.cookie)}
sys.stdout = sys.__stdout__
python
end | 
 
    
      
  
  
    #compile_state(cookie)  ⇒ Object 
  
  
  
  
    | 
27
28
29
30
31
32
33
34
35
36 | # File 'lib/base/query_hook.rb', line 27
def compile_state(cookie)
  (cookie||[]).map do |statement|
<<~python
try:
#{statement}
except:
pass
python
  end
end | 
 
    
      
  
  
    #error_patterns  ⇒ Object 
  
  
  
  
    | 
42
43
44
45
46 | # File 'lib/base/query_hook.rb', line 42
def error_patterns
  [
    Mumukit::ErrorPattern::Errored.new(syntax_error_regexp)
  ]
end | 
 
    
      
  
  
    #syntax_error_regexp  ⇒ Object 
  
  
  
  
    | 
48
49
50 | # File 'lib/base/query_hook.rb', line 48
def syntax_error_regexp
  /(SyntheticMumukiSyntaxError: )|((\A  File .*\n)?(?m)(?=.*(SyntaxError|IndentationError)))/
end |