Package org.python.core

Examples of org.python.core.PyFile


  public Object getStream(String key) {
    final StreamProxy val = Streams.get(key);
    if (val != null) {
      try {
        return new PyFile(val.open(FS));
      }
      catch (IOException ex) {}
    }
    return null;
  }
View Full Code Here


    } else {
      try {
      File fileArg = (File) arg;
      InputStream fileStream = fileArg.toURL().openStream();
      interp.set(argName,
          new PyFile(fileStream));
      } catch (IOException e) {
        logger.log(LogService.LOG_ERROR, "Problem opening file" +
            " provided as an argument to jython script.", e);
        e.printStackTrace();
     
View Full Code Here

        }
    }

    private static PyObject newFile(File file) {
        try {
            return new PyFile(new FileInputStream(file));
        } catch (IOException ioe) {
            throw Py.IOError(ioe);
        }
    }
View Full Code Here

    }

    public static PyObject load_source(String modname, String filename) {
        PyObject mod = Py.None;
        //XXX: bufsize is ignored in PyFile now, but look 3rd arg if this ever changes.
        PyFile file = new PyFile(filename, "r", 1024);
        Object o = file.__tojava__(InputStream.class);
        if (o == Py.NoConversion) {
            throw Py.TypeError("must be a file-like object");
        }
        try {
            mod = org.python.core.imp.createFromSource(modname.intern(), FileUtil.readBytes((InputStream) o),
View Full Code Here

                       throw Py.IOError(e);
                   }
                   try {
                       if (PosixModule.getPOSIX().isatty(file.getFD())) {
                           opts.interactive = true;
                           interp.interact(null, new PyFile(file));
                           return;
                       } else {
                           interp.execfile(file, opts.filename);
                       }
                   } finally {
View Full Code Here

     *
     * @param inStream
     *            InputStream to use as input stream
     */
    public void setIn(java.io.InputStream inStream) {
        setIn(new PyFile(inStream));
    }
View Full Code Here

     *
     * @param outStream
     *            OutputStream to use as output stream
     */
    public void setOut(java.io.OutputStream outStream) {
        setOut(new PyFile(outStream));
    }
View Full Code Here

    public void setErr(java.io.Writer outStream) {
        setErr(new PyFileWriter(outStream));
    }

    public void setErr(java.io.OutputStream outStream) {
        setErr(new PyFile(outStream));
    }
View Full Code Here

    protected String getTestPath(String testName) {
        return "/test/pyservlet/" + testName + ".py";
    }

    private String readTestFile(String testName) {
        PyFile in = new PyFile(basePath + getTestPath(testName), "r", 4192);
        String result = in.read().toString();
        return result;
    }
View Full Code Here

        String result = in.read().toString();
        return result;
    }

    private void writeToTestFile(String testName, String newContents) {
        PyFile out = new PyFile(basePath + getTestPath(testName), "w", 4192);
        out.write(newContents);
        out.close();
    }
View Full Code Here

TOP

Related Classes of org.python.core.PyFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.