"""Imported by app_main.py when PyPy needs to fire up the interactive console."""importsysimportosdefinteractive_console(mainmodule=None):# set sys.{ps1,ps2} just before invoking the interactive interpreter. This# mimics what CPython does in pythonrun.cifnothasattr(sys,'ps1'):sys.ps1='>>>> 'ifnothasattr(sys,'ps2'):sys.ps2='.... '#try:from_pypy_irc_topicimportsome_topictext="And now for something completely different: ``%s''"%(some_topic(),)whilelen(text)>=80:i=text[:80].rfind(' ')printtext[:i]text=text[i+1:]printtextexceptImportError:pass#try:ifnotos.isatty(sys.stdin.fileno()):# Bail out if stdin is not tty-like, as pyrepl wouldn't be happy# For example, with:# subprocess.Popen(['pypy', '-i'], stdin=subprocess.PIPE)raiseImportErrorfrompyrepl.simple_interactimportcheckifnotcheck():raiseImportErrorfrompyrepl.simple_interactimportrun_multiline_interactive_consoleexceptImportError:run_simple_interactive_console(mainmodule)else:run_multiline_interactive_console(mainmodule)defrun_simple_interactive_console(mainmodule):importcodeifmainmoduleisNone:import__main__asmainmoduleconsole=code.InteractiveConsole(mainmodule.__dict__)# some parts of code.py are copied here because it seems to be impossible# to start an interactive console without printing at least one line# of bannermore=0while1:try:ifmore:prompt=getattr(sys,'ps2','... ')else:prompt=getattr(sys,'ps1','>>> ')try:line=raw_input(prompt)# Can be None if sys.stdin was redefinedencoding=getattr(sys.stdin,'encoding',None)ifencodingandnotisinstance(line,unicode):line=line.decode(encoding)exceptEOFError:console.write("\n")breakelse:more=console.push(line)exceptKeyboardInterrupt:console.write("\nKeyboardInterrupt\n")console.resetbuffer()more=0# ____________________________________________________________if__name__=='__main__':# for testingimportosifos.getenv('PYTHONSTARTUP'):execfile(os.getenv('PYTHONSTARTUP'))interactive_console()