Package org.python.core.util

Examples of org.python.core.util.RelativeFile


                   interp.globals.__setitem__(new PyString("__file__"),
                                              new PyString(opts.filename));

                   FileInputStream file;
                   try {
                       file = new FileInputStream(new RelativeFile(opts.filename));
                   } catch (FileNotFoundException e) {
                       throw Py.IOError(e);
                   }
                   try {
                       if (PosixModule.getPOSIX().isatty(file.getFD())) {
View Full Code Here


     * @param name the name of the file
     * @param mode a raw io file mode String
     */
    public FileIO(PyString name, String mode) {
        parseMode(mode);
        File absPath = new RelativeFile(name.toString());

        try {
            if (appending && !(reading || plus)) {
                // Take advantage of FileOutputStream's append mode
                fromFileOutputStream(absPath);
            } else {
                fromRandomAccessFile(absPath);
                emulateAppend = appending;
            }
        } catch (FileNotFoundException fnfe) {
            if (absPath.isDirectory()) {
                throw Py.IOError(Errno.EISDIR, name);
            }
            if ((writing && !absPath.canWrite())
                || fnfe.getMessage().endsWith("(Permission denied)")) {
                throw Py.IOError(Errno.EACCES, name);
            }
            throw Py.IOError(Errno.ENOENT, name);
        }
View Full Code Here

            if (!(entry instanceof PyUnicode)) {
                entry = entry.__str__();
            }
            String dir = entry.toString();

            File f = new RelativeFile(dir, child);
            try {
                if (f.isDirectory() && imp.caseok(f, name)) {
                    /*
                     * Figure out if we have a directory a mixture of python and
                     * java or just an empty directory (which means Java) or a
                     * directory with only Python source (which means Python).
                     */
                    PackageExistsFileFilter m = new PackageExistsFileFilter();
                    f.listFiles(m);
                    boolean exists = m.packageExists();
                    if (exists) {
                        Py.writeComment("import", "java package as '"
                                + f.getAbsolutePath() + "'");
                    }
                    return exists;
                }
            } catch (SecurityException se) {
                return false;
View Full Code Here

                accum += File.separator;
            }
            accum += token;
            first = false;
        }
        return new RelativeFile(dir, accum + ".class");
    }
View Full Code Here

     * @param filename a filename String
     * @param lineno the line number
     * @return a String line or null
     */
    private String getLine(String filename, int lineno) {
        RelativeFile file = new RelativeFile(filename);
        try {
            if (!file.isFile() || !file.canRead()) {
                // XXX: We should run through sys.path until the filename is found
                return null;
            }
        } catch (SecurityException e) {
            return null// If we don't have read access to the file, return null
View Full Code Here

    public static void execfile_flags(String name, PyObject globals, PyObject locals,
                                      CompilerFlags cflags) {
        verify_mappings(globals, locals);
        FileInputStream file;
        try {
            file = new FileInputStream(new RelativeFile(name));
        } catch (FileNotFoundException e) {
            throw Py.IOError(e);
        }
        PyCode code;
View Full Code Here

TOP

Related Classes of org.python.core.util.RelativeFile

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.