#
"""Dieses Script initialisiert den internen Lasal2 Python interpreter."""

def _Lasal2AutoExec() :
  import sys
  import _internal
  
  def _Lasal2ExceptHook(t,v,tr) :
    "Redirects Errors to the lasal2 error logging subsystem"
    import traceback
    lines = traceback.format_exception(t, v, tr)
    str = "".join(lines)
    _internal.logError(str)
  
  class CWrapper :
    str = ""
    def write(self, s) :
      self.str = self.str + s
  
  class CWrapper2 :
    def write(self, s) :
      _internal.write(s)
    def flush(self) :
      pass
  
  
  # erste Methode leitet stderr kurzfristig um
  def _Lasal2ExceptHook2(t,v,tr) :
    "Redirects Errors to the lasal2 error logging subsystem"
    w = CWrapper()	
    o = sys.stderr
    sys.stderr = w
    sys.__excepthook__(t,v,tr)
    sys.stderr = o
    _internal.logError(w.str.rstrip("\n\r "))
    _internal.write(w.str)
  
  # Hook zur Exception-Umleitung installieren
  sys.excepthook = _Lasal2ExceptHook2
  
  # Ausgabe umleiten
  sys.stdout = CWrapper2()
  sys.stderr = CWrapper2()  
  
  # Pfad zur Python-Standardlibrary anhaengen
  sys.path.append(sys.prefix+"\\lib.zip")
  
  # Pfad fuer TK
  sys.path.append(sys.prefix+"\\lib.zip\\plat-win")
  sys.path.append(sys.prefix+"\\lib.zip\\lib-tk")
  sys.path.append(sys.prefix+"\\tcl")  
  
  # nochmal Default-Modul importieren (fuer help etc.)
  import site

# diese Prozedur ausfuehren
_Lasal2AutoExec()