#!/usr/bin/python3
"""Entry point of the Python port of sophomorix-exam-mode (called by the dispatcher)."""
import os
import sys
sys.path.insert(0, '/usr/share/sophomorix-nextgen')

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

for stream in (sys.stdout, sys.stderr):
    stream.reconfigure(encoding="utf-8", errors="surrogateescape")

from sophomorix_py.exam_cli import main  # noqa: E402
from sophomorix_py.runtime import R  # noqa: E402

try:
    raise SystemExit(main(sys.argv[1:]))
except SystemExit as e:
    R.flush()
    raise
