def _find_file(self, interp, fname): if not exists(fname): for path in interp.include_path: if exists(join(path, [fname])): return join(path, [fname]) # this is stupid, but... actual_code_dir = dirname(interp.global_frame.bytecode.filename) if exists(join(actual_code_dir, [fname])): return join(actual_code_dir, [fname]) return abspath(fname)
def compile_file(self, fname, space): absname = abspath(fname) now = time.time() try: bc, tstamp = self.cached_files[absname] if now - tstamp >= self.timeout: mtime = os.stat(absname).st_mtime if mtime > tstamp: raise KeyError except KeyError: f = open(absname) data = f.read(-1) f.close() tstamp = os.stat(absname).st_mtime bc = compile_php(absname, data, space) self.cached_files[absname] = (bc, tstamp) return bc
def main(filename, rest_of_args, cgi, gcdump, debugger_pipes=(-1, -1), bench_mode=False, bench_no=-1): space = getspace() interp = Interpreter(space) absname = rpath.abspath(filename) try: ini_data = open('hippy.ini').read(-1) except (OSError, IOError): ini_data = None if ini_data is not None: try: load_ini(interp, ini_data) except: os.write(2, "error reading `hippy.ini`") try: bc = space.bytecode_cache.compile_file(absname, space) except ParseError as e: print 'Parse error: %s' % e return 2 except LexerError as e: print 'Parse error: %s on line %d' % (e.message, e.source_pos + 1) return 2 except IOError as e: print 'Could not open input file: %s' % filename return 2 except Exception as e: print 'Got exception %s with message %s' % (e.__class__.__name__, e) return 2 # if bench_mode: no = bench_no else: no = 1 exitcode = 0 space.ec.init_signals() for i in range(no): # load the ini file situated in the current wc interp.setup(cgi, argv=[filename] + rest_of_args) if bc is None: return 1 # The script originally called is considered an "included file," # so it will be listed together with the files # referenced by include and family. interp.cached_files[filename] = bc # exitcode = 0 try: try: if debugger_pipes != (-1, -1): interp.setup_debugger(debugger_pipes[0], debugger_pipes[1], start_paused=True) interp.run_main(space, bc, top_main=True) finally: interp.shutdown() except InterpreterError, e: tb = e.traceback if tb is not None: tb = tb[:] tb.reverse() for filename, funcname, line, source in tb: os.write( 2, "function %s, file %s:%d\n" % (funcname, filename, line)) os.write(2, source + "\n") if we_are_translated(): os.write(2, "Fatal interpreter error %s\n" % e.msg) else: print >> sys.stderr, "%s: %s\n" % (e.__class__.__name__, e.msg) except ParseError as e: print e.__str__() return 1
def main(filename, rest_of_args, cgi, gcdump, debugger_pipes=(-1, -1), bench_mode=False, bench_no=-1): space = getspace() interp = Interpreter(space) absname = rpath.abspath(filename) try: ini_data = open('hippy.ini').read(-1) except (OSError, IOError): ini_data = None if ini_data is not None: try: load_ini(interp, ini_data) except: os.write(2, "error reading `hippy.ini`") try: bc = space.bytecode_cache.compile_file(absname, space) except: print "Error opening %s" % filename return 2 # if bench_mode: no = bench_no else: no = 1 exitcode = 0 for i in range(no): # load the ini file situated in the current wc interp.setup(cgi, argv=[filename] + rest_of_args) if bc is None: return 1 # The script originally called is considered an "included file," # so it will be listed together with the files # referenced by include and family. interp.cached_files[filename] = bc # exitcode = 0 try: try: if debugger_pipes != (-1, -1): interp.setup_debugger(debugger_pipes[0], debugger_pipes[1], start_paused=True) interp.run_main(space, bc, top_main=True) finally: interp.shutdown() except InterpreterError, e: tb = e.traceback if tb is not None: tb = tb[:] tb.reverse() for filename, funcname, line, source in tb: os.write(2, "function %s, file %s:%d\n" % (funcname, filename, line)) os.write(2, source + "\n") if we_are_translated(): os.write(2, "Fatal interpreter error %s\n" % e.msg) else: print >>sys.stderr, "%s: %s\n" % (e.__class__.__name__, e.msg) except ParseError as e: print e.__str__() return 1