package com.jetbrains.python;

import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import org.jetbrains.annotations.NonNls;
import org.python.core.PyObject;
import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author yole
 */
public class JythonManager {
  private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.JythonManager");

  public static JythonManager getInstance() {
    return ServiceManager.getService(JythonManager.class);
  }

  private PythonInterpreter myInterpreter;

  public JythonManager() {
    @NonNls Properties postProperties = new Properties();
    postProperties.put("python.cachedir.skip", "true");
    PySystemState.initialize(PySystemState.getBaseProperties(), postProperties, new String[] { "" });
    myInterpreter = new PythonInterpreter();
  }

  public void execScriptFromResource(@NonNls String resourcePath) {
    final InputStream stream = getClass().getClassLoader().getResourceAsStream(resourcePath);
    if (stream != null) { // TODO: stream == null seems to indicate some build problem?
      try {
        myInterpreter.execfile(stream);
      }
      finally {
        try {
          stream.close();
        }
        catch (IOException e) {
          LOG.error(e);
        }
      }
    }
  }

  public PyObject eval(@NonNls final String code) {
    return myInterpreter.eval(code);
  }
}

@@ -1129,98 +1129,8 @@
 h);%0A
-    if (stream != null) %7B // TODO: stream == null seems to indicate some build problem?%0A  
     
@@ -1131,26 +1131,24 @@
 ;%0A    try %7B%0A
-  
       myInte
@@ -1177,26 +1177,22 @@
 m);%0A    
-  
 %7D%0A    
- 
- 
 finally 
@@ -1199,18 +1199,16 @@
 %7B%0A      
-  
 try %7B%0A  
@@ -1213,18 +1213,16 @@
         
- 
- 
 stream.c
@@ -1229,18 +1229,16 @@
 lose();%0A
-  
       %7D%0A
@@ -1243,18 +1243,16 @@
 %7D%0A      
-  
 catch (I
@@ -1275,18 +1275,16 @@
         
-  
 LOG.erro
@@ -1293,18 +1293,8 @@
 e);%0A
-        %7D%0A
     

remove incorrect null check