Class: Python3QueryHook

Inherits:
BasePythonQueryHook show all
Defined in:
lib/python3/query_hook.rb

Instance Method Summary collapse

Methods inherited from BasePythonQueryHook

#command_line, #compile_cookie, #compile_file_content, #compile_file_header, #compile_state, #error_patterns, #syntax_error_regexp

Instance Method Details

#compile_query(query, output_prefix = "=> ") ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/python3/query_hook.rb', line 2

def compile_query(query, output_prefix = "=> ")
<<~python
import code
import itertools
import traceback
import sys

__mumuki_console__ = code.InteractiveConsole()

try:
__mumuki_result__ = __mumuki_console__.compile("""#{query.gsub('"', '\"')}""")
if __mumuki_result__ != None:
  exec(__mumuki_result__)
else:
  raise SyntaxError('unexpected EOF while parsing')
except:
error = sys.exc_info()
stack = traceback.format_exception(*error)
print(*itertools.dropwhile(lambda it: 'File "<input>"' not in it and not it.startswith("SyntaxError"), stack))
exit(1)
python
end