Execute the parse expression on the given file or filename.
           If a filename is specified (instead of a file object),
           the entire file is opened, read, and closed before parsing.
559132
def parseFile( self, file_or_filename ):
        
        try:
            file_contents = file_or_filename.read()
        except AttributeError:
            f = open(file_or_filename, "rb")
            file_contents = f.read()
            f.close()
        return self.parseString(file_contents)
436535
def from_file(filename_or_file_object):
    
    if isinstance(filename_or_file_object, basestring):
        file_ = open(filename_or_file_object, 'r')
        we_opened = True
    else:
        we_opened = False
        file_ = filename_or_file_object

    try:
        data = load(file_.read())
    finally:
        if we_opened:
            file_.close()

    return data
31741
def parse_file(self, filename, skip_unreadable=False):
        
        if not os.access(filename, os.R_OK):
            if skip_unreadable:
                return
            raise ConfigReadingError("Unable to open file %s." % filename)
        with open(filename, 'rt') as f:
            return self.parse(f, name_hint=filename)
762779
private void parseFile(File file) throws Exception {
        int lineNumber = 1;
        String line = null;
        BufferedReader in = null;
        try {
            in = new BufferedReader(new FileReader(file));
            List<TZDBZone> openZone = null;
            for ( ; (line = in.readLine()) != null; lineNumber++) {
                int index = line.indexOf('#');  // remove comments (doesn't handle # in quotes)
                if (index >= 0) {
                    line = line.substring(0, index);
                }
                if (line.trim().length() == 0) {  // ignore blank lines
                    continue;
                }
                StringTokenizer st = new StringTokenizer(line, " \t");
                if (openZone != null && Character.isWhitespace(line.charAt(0)) && st.hasMoreTokens()) {
                    if (parseZoneLine(st, openZone)) {
                        openZone = null;
                    }
                } else {
                    if (st.hasMoreTokens()) {
                        String first = st.nextToken();
                        if (first.equals("Zone")) {
                            if (st.countTokens() < 3) {
                                printVerbose("Invalid Zone line in file: " + file + ", line: " + line);
                                throw new IllegalArgumentException("Invalid Zone line");
                            }
                            openZone = new ArrayList<TZDBZone>();
                            zones.put(st.nextToken(), openZone);
                            if (parseZoneLine(st, openZone)) {
                                openZone = null;
                            }
                        } else {
                            openZone = null;
                            if (first.equals("Rule")) {
                                if (st.countTokens() < 9) {
                                    printVerbose("Invalid Rule line in file: " + file + ", line: " + line);
                                    throw new IllegalArgumentException("Invalid Rule line");
                                }
                                parseRuleLine(st);

                            } else if (first.equals("Link")) {
                                if (st.countTokens() < 2) {
                                    printVerbose("Invalid Link line in file: " + file + ", line: " + line);
                                    throw new IllegalArgumentException("Invalid Link line");
                                }
                                String realId = st.nextToken();
                                String aliasId = st.nextToken();
                                links.put(aliasId, realId);

                            } else {
                                throw new IllegalArgumentException("Unknown line");
                            }
                        }
                    }
                }
            }
        } catch (Exception ex) {
            throw new Exception("Failed while processing file '" + file + "' on line " + lineNumber + " '" + line + "'", ex);
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
495161
public Collection<XLog> parse(File file) throws Exception {
		Collection<XLog> result = null;
		for(XParser parser : XParserRegistry.instance().getAvailable()) {
			if(parser.canParse(file)) {
				try {
					result = parser.parse(file);
					return result;
				} catch(Exception e) {
					// ignore and move on
				}
			}
		}
		throw new Exception("No suitable parser could be found!");
	}
449610
def parse_file(self, filename, encoding=None, debug=False):
        """"""
        stream = codecs.open(filename, "r", encoding)
        try:
            return self.parse_stream(stream, debug)
        finally:
            stream.close()
271258
def load_file(self, filename):
        
        self._say("Loading file: " + filename)

        fh    = codecs.open(filename, 'r', 'utf-8')
        lines = fh.readlines()
        fh.close()

        self._say("Parsing " + str(len(lines)) + " lines of code from " + filename)
        self._parse(filename, lines)
1359355
public void parse(final String filename, final File dir) {
        filePath = stripFragment(filename);
        dirPath = dir;
        try {
            final File f = new File(dir, filePath);
            reader.setErrorHandler(new DITAOTXMLErrorHandler(f.getAbsolutePath(), logger));
            logger.info("Processing " + f.getAbsolutePath());
            reader.parse(f.toURI().toString());
        } catch (final RuntimeException e) {
            throw e;
        } catch (final Exception e) {
            throw new RuntimeException("Failed to parse " + filename + ": " + e.getMessage(), e);
        }
    }
892342
def open(filename):
	
	buffer = _builtin_open(filename, 'rb')
	try:
		encoding, lines = detect_encoding(buffer.readline)
		buffer.seek(0)
		text = TextIOWrapper(buffer, encoding, line_buffering=True)
		text.mode = 'r'
		return text
	except:
		buffer.close()
		raise
988797
private static Process action(final String fileName,
			String parameters, boolean waitForTermination) throws IOException {
		Process process = null;
		if (parameters.trim().length() > 0) {
			parameters = " " + parameters.trim();
		}
		else {
			parameters = "";
		}
		if (acroread != null) {
			process = Runtime.getRuntime().exec(
					acroread + parameters + " \"" + fileName + "\"");
		}
		else if (isWindows()) {
			if (isWindows9X()) {
				process = Runtime.getRuntime().exec(
						"command.com /C start acrord32" + parameters + " \"" + fileName + "\"");
			}
			else {
				process = Runtime.getRuntime().exec(
					"cmd /c start acrord32" + parameters + " \"" + fileName + "\"");
			}
		}
		else if (isMac()) {
			if (parameters.trim().length() == 0) {
				process = Runtime.getRuntime().exec(
					new String[] { "/usr/bin/open", fileName });
			}
			else {
				process = Runtime.getRuntime().exec(
						new String[] { "/usr/bin/open", parameters.trim(), fileName });
			}
		}
		try {
			if (process != null && waitForTermination)
				process.waitFor();
		} catch (InterruptedException ie) {
		}
		return process;
	}
290897
def evaluate(self, node, filename=None):
        
        if isinstance(node, string_types):
            self.source = node
            kwargs = {'mode': 'eval'}
            if filename:
                kwargs['filename'] = filename
            try:
                node = ast.parse(node, **kwargs)
            except SyntaxError as e:
                s = self.get_fragment(e.offset)
                raise SyntaxError('syntax error %s' % s)
        node_type = node.__class__.__name__.lower()
        handler = self.get_handler(node_type)
        if handler is None:
            if self.source is None:
                s = '(source not available)'
            else:
                s = self.get_fragment(node.col_offset)
            raise SyntaxError("don't know how to evaluate %r %s" % (
                node_type, s))
        return handler(node)
6641
def runfile(self, filename, args=None):
        
        if args is not None and not is_text_string(args):
            raise TypeError("expected a character buffer object")
        self.namespace['__file__'] = filename
        sys.argv = [filename]
        if args is not None:
            for arg in args.split():
                sys.argv.append(arg)
        self.execfile(filename)
        sys.argv = ['']
        self.namespace.pop('__file__')
482394
function (filename) {
		var resume = filename === true; // should only ever be set by resume calls
		var fd = this._fd = resume ? this._fd : fs.openSync(filename, 'r');
		var buffer = new Buffer(4096);
		var bytesRead;
		var current = '';
		var remainder = resume ? this._remainder : '';

		while (!this._paused && (bytesRead = fs.readSync(fd, buffer, 0, buffer.length))) {
			current = buffer.toString('utf-8');
			if (current.length > bytesRead) {
				current = current.slice(0, bytesRead);
			}
			remainder = this._remainder = this._parseLines(remainder + current);
		}

		// The loop will end either when EOF is reached, or pause was called.
		// In the former case, close the file; in the latter case, leave it
		// open with the expectation that we'll pick up where we left off.
		if (!this._paused) {
			fs.closeSync(fd);
		}
	}
753361
def _loadSession(self, filename):
        
        try:
            self.eval(open(filename).read())
        except RuntimeError as e:
            print(e)
625224
public synchronized void setFilename(String filename)
    {
        if (filename!=null)
        {
            filename=filename.trim();
            if (filename.length()==0)
                filename=null;
        }
        
        if (isStarted() && _filename!=null && filename==null)
            _out=null;
        
        _reopen=isStarted() &&
            ((_filename==null && filename!=null)||
             (_filename!=null && !_filename.equals(filename)));
        _filename=filename;

        if (!isStarted() && _filename!=null)
            _out=null;
    }
169560
def execute(argv, filename='Runfile')
      @ignore_settings = !filename
      argv = expand_shortcuts argv
      filename and File.file?(filename) or handle_no_runfile argv

      begin
        load settings.helper if settings.helper
        load filename
      rescue => ex
        abort "Runfile error:\n#{ex.message}\n#{ex.backtrace[0]}"
      end
      run(*argv)
    end
95275
public static void processSource(Context cx, String filename)
            throws IOException
    {
        if (filename == null || filename.equals("-")) {
            Scriptable scope = getShellScope();
            Charset cs;
            String charEnc = shellContextFactory.getCharacterEncoding();
            if (charEnc != null) {
                cs = Charset.forName(charEnc);
            } else {
                cs = Charset.defaultCharset();
            }
            ShellConsole console = global.getConsole(cs);
            if (filename == null) {
                // print implementation version
                console.println(cx.getImplementationVersion());
            }

            int lineno = 1;
            boolean hitEOF = false;
            while (!hitEOF) {
                String[] prompts = global.getPrompts(cx);
                String prompt = null;
                if (filename == null)
                    prompt = prompts[0];
                console.flush();
                String source = "";

                // Collect lines of source to compile.
                while (true) {
                    String newline;
                    try {
                        newline = console.readLine(prompt);
                    }
                    catch (IOException ioe) {
                        console.println(ioe.toString());
                        break;
                    }
                    if (newline == null) {
                        hitEOF = true;
                        break;
                    }
                    source = source + newline + "\n";
                    lineno++;
                    if (cx.stringIsCompilableUnit(source))
                        break;
                    prompt = prompts[1];
                }
                try {
                    Script script = cx.compileString(source, "<stdin>", lineno, null);
                    if (script != null) {
                        Object result = script.exec(cx, scope);
                        // Avoid printing out undefined or function definitions.
                        if (result != Context.getUndefinedValue() &&
                                !(result instanceof Function &&
                                        source.trim().startsWith("function")))
                        {
                            try {
                                console.println(Context.toString(result));
                            } catch (RhinoException rex) {
                                ToolErrorReporter.reportException(
                                        cx.getErrorReporter(), rex);
                            }
                        }
                        NativeArray h = global.history;
                        h.put((int)h.getLength(), h, source);
                    }
                } catch (RhinoException rex) {
                    ToolErrorReporter.reportException(
                        cx.getErrorReporter(), rex);
                    exitCode = EXITCODE_RUNTIME_ERROR;
                } catch (VirtualMachineError ex) {
                    // Treat StackOverflow and OutOfMemory as runtime errors
                    ex.printStackTrace();
                    String msg = ToolErrorReporter.getMessage(
                        "msg.uncaughtJSException", ex.toString());
                    Context.reportError(msg);
                    exitCode = EXITCODE_RUNTIME_ERROR;
                }
            }
            console.println();
            console.flush();
        } else if (useRequire && filename.equals(mainModule)) {
            require.requireMain(cx, filename);
        } else {
            processFile(cx, getScope(filename), filename);
        }
    }