Class: Python3QueryHook
- Inherits:
-
BasePythonQueryHook
- Object
- Mumukit::Templates::FileHook
- BasePythonQueryHook
- Python3QueryHook
- 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 = "=> ") "import code\nimport itertools\nimport traceback\nimport sys\n\n__mumuki_console__ = code.InteractiveConsole()\n\ntry:\n__mumuki_result__ = __mumuki_console__.compile(\"\"\"\#{query.gsub('\"', '\\\"')}\"\"\")\nif __mumuki_result__ != None:\n exec(__mumuki_result__)\nelse:\n raise SyntaxError('unexpected EOF while parsing')\nexcept:\nerror = sys.exc_info()\nstack = traceback.format_exception(*error)\nprint(*itertools.dropwhile(lambda it: 'File \"<input>\"' not in it and not it.startswith(\"SyntaxError\"), stack))\nexit(1)\n" end |