<s> from __future__ import print_function <EOL> import os <EOL> import os . path <EOL> import sys <EOL> import string <EOL> import getopt <EOL> import re <EOL> import socket <EOL> import time <EOL> import threading <EOL> import io <EOL> import linecache <EOL> from code import InteractiveInterpreter <EOL> from platform import python_version , system <EOL> try : <EOL> from Tkinter import * <EOL> except ImportError : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" , file = sys . __stderr__ ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> import tkMessageBox <EOL> from idlelib . EditorWindow import EditorWindow , fixwordbreaks <EOL> from idlelib . FileList import FileList <EOL> from idlelib . ColorDelegator import ColorDelegator <EOL> from idlelib . UndoDelegator import UndoDelegator <EOL> from idlelib . OutputWindow import OutputWindow <EOL> from idlelib . configHandler import idleConf <EOL> from idlelib import rpc <EOL> from idlelib import Debugger <EOL> from idlelib import RemoteDebugger <EOL> from idlelib import macosxSupport <EOL> from idlelib import IOBinding <EOL> IDENTCHARS = string . ascii_letters + string . digits + "<STR_LIT:_>" <EOL> HOST = '<STR_LIT:127.0.0.1>' <EOL> PORT = <NUM_LIT:0> <EOL> try : <EOL> from signal import SIGTERM <EOL> except ImportError : <EOL> SIGTERM = <NUM_LIT:15> <EOL> warning_stream = sys . __stderr__ <EOL> import warnings <EOL> def idle_formatwarning ( message , category , filename , lineno , line = None ) : <EOL> """<STR_LIT>""" <EOL> s = "<STR_LIT>" <EOL> s += '<STR_LIT>' % ( filename , lineno ) <EOL> if line is None : <EOL> line = linecache . getline ( filename , lineno ) <EOL> line = line . strip ( ) <EOL> if line : <EOL> s += "<STR_LIT>" % line <EOL> s += "<STR_LIT>" % ( category . __name__ , message ) <EOL> return s <EOL> def idle_showwarning ( <EOL> message , category , filename , lineno , file = None , line = None ) : <EOL> """<STR_LIT>""" <EOL> if file is None : <EOL> file = warning_stream <EOL> try : <EOL> file . write ( idle_formatwarning ( <EOL> message , category , filename , lineno , line = line ) ) <EOL> file . write ( "<STR_LIT>" ) <EOL> except ( AttributeError , IOError ) : <EOL> pass <EOL> _warnings_showwarning = None <EOL> def capture_warnings ( capture ) : <EOL> "<STR_LIT>" <EOL> global _warnings_showwarning <EOL> if capture : <EOL> if _warnings_showwarning is None : <EOL> _warnings_showwarning = warnings . showwarning <EOL> warnings . showwarning = idle_showwarning <EOL> else : <EOL> if _warnings_showwarning is not None : <EOL> warnings . showwarning = _warnings_showwarning <EOL> _warnings_showwarning = None <EOL> capture_warnings ( True ) <EOL> def extended_linecache_checkcache ( filename = None , <EOL> orig_checkcache = linecache . checkcache ) : <EOL> """<STR_LIT>""" <EOL> cache = linecache . cache <EOL> save = { } <EOL> for key in list ( cache ) : <EOL> if key [ : <NUM_LIT:1> ] + key [ - <NUM_LIT:1> : ] == '<STR_LIT>' : <EOL> save [ key ] = cache . pop ( key ) <EOL> orig_checkcache ( filename ) <EOL> cache . update ( save ) <EOL> linecache . checkcache = extended_linecache_checkcache <EOL> class PyShellEditorWindow ( EditorWindow ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , * args ) : <EOL> self . breakpoints = [ ] <EOL> EditorWindow . __init__ ( self , * args ) <EOL> self . text . bind ( "<STR_LIT>" , self . set_breakpoint_here ) <EOL> self . text . bind ( "<STR_LIT>" , self . clear_breakpoint_here ) <EOL> self . text . bind ( "<STR_LIT>" , self . flist . open_shell ) <EOL> self . breakpointPath = os . path . join ( idleConf . GetUserCfgDir ( ) , <EOL> '<STR_LIT>' ) <EOL> def filename_changed_hook ( old_hook = self . io . filename_change_hook , <EOL> self = self ) : <EOL> self . restore_file_breaks ( ) <EOL> old_hook ( ) <EOL> self . io . set_filename_change_hook ( filename_changed_hook ) <EOL> if self . io . filename : <EOL> self . restore_file_breaks ( ) <EOL> self . color_breakpoint_text ( ) <EOL> rmenu_specs = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , None ) <EOL> ] <EOL> def color_breakpoint_text ( self , color = True ) : <EOL> "<STR_LIT>" <EOL> if self . io is None : <EOL> return <EOL> if color : <EOL> theme = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ) <EOL> cfg = idleConf . GetHighlight ( theme , "<STR_LIT>" ) <EOL> else : <EOL> cfg = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> self . text . tag_config ( '<STR_LIT>' , cfg ) <EOL> def set_breakpoint ( self , lineno ) : <EOL> text = self . text <EOL> filename = self . io . filename <EOL> text . tag_add ( "<STR_LIT>" , "<STR_LIT>" % lineno , "<STR_LIT>" % ( lineno + <NUM_LIT:1> ) ) <EOL> try : <EOL> self . breakpoints . index ( lineno ) <EOL> except ValueError : <EOL> self . breakpoints . append ( lineno ) <EOL> try : <EOL> debug = self . flist . pyshell . interp . debugger <EOL> debug . set_breakpoint_here ( filename , lineno ) <EOL> except : <EOL> pass <EOL> def set_breakpoint_here ( self , event = None ) : <EOL> text = self . text <EOL> filename = self . io . filename <EOL> if not filename : <EOL> text . bell ( ) <EOL> return <EOL> lineno = int ( float ( text . index ( "<STR_LIT>" ) ) ) <EOL> self . set_breakpoint ( lineno ) <EOL> def clear_breakpoint_here ( self , event = None ) : <EOL> text = self . text <EOL> filename = self . io . filename <EOL> if not filename : <EOL> text . bell ( ) <EOL> return <EOL> lineno = int ( float ( text . index ( "<STR_LIT>" ) ) ) <EOL> try : <EOL> self . breakpoints . remove ( lineno ) <EOL> except : <EOL> pass <EOL> text . tag_remove ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> try : <EOL> debug = self . flist . pyshell . interp . debugger <EOL> debug . clear_breakpoint_here ( filename , lineno ) <EOL> except : <EOL> pass <EOL> def clear_file_breaks ( self ) : <EOL> if self . breakpoints : <EOL> text = self . text <EOL> filename = self . io . filename <EOL> if not filename : <EOL> text . bell ( ) <EOL> return <EOL> self . breakpoints = [ ] <EOL> text . tag_remove ( "<STR_LIT>" , "<STR_LIT:1.0>" , END ) <EOL> try : <EOL> debug = self . flist . pyshell . interp . debugger <EOL> debug . clear_file_breaks ( filename ) <EOL> except : <EOL> pass <EOL> def store_file_breaks ( self ) : <EOL> "<STR_LIT>" <EOL> breaks = self . breakpoints <EOL> filename = self . io . filename <EOL> try : <EOL> with open ( self . breakpointPath , "<STR_LIT:r>" ) as old_file : <EOL> lines = old_file . readlines ( ) <EOL> except IOError : <EOL> lines = [ ] <EOL> try : <EOL> with open ( self . breakpointPath , "<STR_LIT:w>" ) as new_file : <EOL> for line in lines : <EOL> if not line . startswith ( filename + '<STR_LIT:=>' ) : <EOL> new_file . write ( line ) <EOL> self . update_breakpoints ( ) <EOL> breaks = self . breakpoints <EOL> if breaks : <EOL> new_file . write ( filename + '<STR_LIT:=>' + str ( breaks ) + '<STR_LIT:\n>' ) <EOL> except IOError as err : <EOL> if not getattr ( self . root , "<STR_LIT>" , False ) : <EOL> self . root . breakpoint_error_displayed = True <EOL> tkMessageBox . showerror ( title = '<STR_LIT>' , <EOL> message = '<STR_LIT>' <EOL> % str ( err ) , <EOL> parent = self . text ) <EOL> def restore_file_breaks ( self ) : <EOL> self . text . update ( ) <EOL> if self . io is None : <EOL> return <EOL> filename = self . io . filename <EOL> if filename is None : <EOL> return <EOL> if os . path . isfile ( self . breakpointPath ) : <EOL> lines = open ( self . breakpointPath , "<STR_LIT:r>" ) . readlines ( ) <EOL> for line in lines : <EOL> if line . startswith ( filename + '<STR_LIT:=>' ) : <EOL> breakpoint_linenumbers = eval ( line [ len ( filename ) + <NUM_LIT:1> : ] ) <EOL> for breakpoint_linenumber in breakpoint_linenumbers : <EOL> self . set_breakpoint ( breakpoint_linenumber ) <EOL> def update_breakpoints ( self ) : <EOL> "<STR_LIT>" <EOL> text = self . text <EOL> ranges = text . tag_ranges ( "<STR_LIT>" ) <EOL> linenumber_list = self . ranges_to_linenumbers ( ranges ) <EOL> self . breakpoints = linenumber_list <EOL> def ranges_to_linenumbers ( self , ranges ) : <EOL> lines = [ ] <EOL> for index in range ( <NUM_LIT:0> , len ( ranges ) , <NUM_LIT:2> ) : <EOL> lineno = int ( float ( ranges [ index ] . string ) ) <EOL> end = int ( float ( ranges [ index + <NUM_LIT:1> ] . string ) ) <EOL> while lineno < end : <EOL> lines . append ( lineno ) <EOL> lineno += <NUM_LIT:1> <EOL> return lines <EOL> def _close ( self ) : <EOL> "<STR_LIT>" <EOL> self . clear_file_breaks ( ) <EOL> EditorWindow . _close ( self ) <EOL> class PyShellFileList ( FileList ) : <EOL> "<STR_LIT>" <EOL> EditorWindow = PyShellEditorWindow <EOL> pyshell = None <EOL> def open_shell ( self , event = None ) : <EOL> if self . pyshell : <EOL> self . pyshell . top . wakeup ( ) <EOL> else : <EOL> self . pyshell = PyShell ( self ) <EOL> if self . pyshell : <EOL> if not self . pyshell . begin ( ) : <EOL> return None <EOL> return self . pyshell <EOL> class ModifiedColorDelegator ( ColorDelegator ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> ColorDelegator . __init__ ( self ) <EOL> self . LoadTagDefs ( ) <EOL> def recolorize_main ( self ) : <EOL> self . tag_remove ( "<STR_LIT>" , "<STR_LIT:1.0>" , "<STR_LIT>" ) <EOL> self . tag_add ( "<STR_LIT>" , "<STR_LIT:1.0>" , "<STR_LIT>" ) <EOL> ColorDelegator . recolorize_main ( self ) <EOL> def LoadTagDefs ( self ) : <EOL> ColorDelegator . LoadTagDefs ( self ) <EOL> theme = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ) <EOL> self . tagdefs . update ( { <EOL> "<STR_LIT>" : { '<STR_LIT>' : None , '<STR_LIT>' : None } , <EOL> "<STR_LIT>" : idleConf . GetHighlight ( theme , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : idleConf . GetHighlight ( theme , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : idleConf . GetHighlight ( theme , "<STR_LIT>" ) , <EOL> } ) <EOL> def removecolors ( self ) : <EOL> for tag in self . tagdefs : <EOL> self . tag_remove ( tag , "<STR_LIT>" , "<STR_LIT:end>" ) <EOL> class ModifiedUndoDelegator ( UndoDelegator ) : <EOL> "<STR_LIT>" <EOL> def insert ( self , index , chars , tags = None ) : <EOL> try : <EOL> if self . delegate . compare ( index , "<STR_LIT:<>" , "<STR_LIT>" ) : <EOL> self . delegate . bell ( ) <EOL> return <EOL> except TclError : <EOL> pass <EOL> UndoDelegator . insert ( self , index , chars , tags ) <EOL> def delete ( self , index1 , index2 = None ) : <EOL> try : <EOL> if self . delegate . compare ( index1 , "<STR_LIT:<>" , "<STR_LIT>" ) : <EOL> self . delegate . bell ( ) <EOL> return <EOL> except TclError : <EOL> pass <EOL> UndoDelegator . delete ( self , index1 , index2 ) <EOL> class MyRPCClient ( rpc . RPCClient ) : <EOL> def handle_EOF ( self ) : <EOL> "<STR_LIT>" <EOL> raise EOFError <EOL> class ModifiedInterpreter ( InteractiveInterpreter ) : <EOL> def __init__ ( self , tkconsole ) : <EOL> self . tkconsole = tkconsole <EOL> locals = sys . modules [ '<STR_LIT:__main__>' ] . __dict__ <EOL> InteractiveInterpreter . __init__ ( self , locals = locals ) <EOL> self . save_warnings_filters = None <EOL> self . restarting = False <EOL> self . subprocess_arglist = None <EOL> self . port = PORT <EOL> self . original_compiler_flags = self . compile . compiler . flags <EOL> _afterid = None <EOL> rpcclt = None <EOL> rpcpid = None <EOL> def spawn_subprocess ( self ) : <EOL> if self . subprocess_arglist is None : <EOL> self . subprocess_arglist = self . build_subprocess_arglist ( ) <EOL> args = self . subprocess_arglist <EOL> self . rpcpid = os . spawnv ( os . P_NOWAIT , sys . executable , args ) <EOL> def build_subprocess_arglist ( self ) : <EOL> assert ( self . port != <NUM_LIT:0> ) , ( <EOL> "<STR_LIT>" ) <EOL> w = [ '<STR_LIT>' + s for s in sys . warnoptions ] <EOL> if <NUM_LIT:1> / <NUM_LIT:2> > <NUM_LIT:0> : <EOL> w . append ( '<STR_LIT>' ) <EOL> del_exitf = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> default = False , type = '<STR_LIT:bool>' ) <EOL> if __name__ == '<STR_LIT>' : <EOL> command = "<STR_LIT>" % ( del_exitf , ) <EOL> else : <EOL> command = "<STR_LIT>" % ( del_exitf , ) <EOL> if sys . platform [ : <NUM_LIT:3> ] == '<STR_LIT>' and '<STR_LIT:U+0020>' in sys . executable : <EOL> decorated_exec = '<STR_LIT>' % sys . executable <EOL> else : <EOL> decorated_exec = sys . executable <EOL> return [ decorated_exec ] + w + [ "<STR_LIT:-c>" , command , str ( self . port ) ] <EOL> def start_subprocess ( self ) : <EOL> addr = ( HOST , self . port ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> time . sleep ( i ) <EOL> try : <EOL> self . rpcclt = MyRPCClient ( addr ) <EOL> break <EOL> except socket . error : <EOL> pass <EOL> else : <EOL> self . display_port_binding_error ( ) <EOL> return None <EOL> self . port = self . rpcclt . listening_sock . getsockname ( ) [ <NUM_LIT:1> ] <EOL> if PORT != <NUM_LIT:0> : <EOL> self . rpcclt . listening_sock . setsockopt ( socket . SOL_SOCKET , <EOL> socket . SO_REUSEADDR , <NUM_LIT:1> ) <EOL> self . spawn_subprocess ( ) <EOL> self . rpcclt . listening_sock . settimeout ( <NUM_LIT:10> ) <EOL> try : <EOL> self . rpcclt . accept ( ) <EOL> except socket . timeout : <EOL> self . display_no_subprocess_error ( ) <EOL> return None <EOL> self . rpcclt . register ( "<STR_LIT>" , self . tkconsole ) <EOL> self . rpcclt . register ( "<STR_LIT>" , self . tkconsole . stdin ) <EOL> self . rpcclt . register ( "<STR_LIT>" , self . tkconsole . stdout ) <EOL> self . rpcclt . register ( "<STR_LIT>" , self . tkconsole . stderr ) <EOL> self . rpcclt . register ( "<STR_LIT>" , self . tkconsole . flist ) <EOL> self . rpcclt . register ( "<STR_LIT>" , linecache ) <EOL> self . rpcclt . register ( "<STR_LIT>" , self ) <EOL> self . transfer_path ( with_cwd = True ) <EOL> self . poll_subprocess ( ) <EOL> return self . rpcclt <EOL> def restart_subprocess ( self , with_cwd = False ) : <EOL> if self . restarting : <EOL> return self . rpcclt <EOL> self . restarting = True <EOL> debug = self . getdebugger ( ) <EOL> if debug : <EOL> try : <EOL> RemoteDebugger . close_subprocess_debugger ( self . rpcclt ) <EOL> except : <EOL> pass <EOL> self . rpcclt . close ( ) <EOL> self . unix_terminate ( ) <EOL> console = self . tkconsole <EOL> was_executing = console . executing <EOL> console . executing = False <EOL> self . spawn_subprocess ( ) <EOL> try : <EOL> self . rpcclt . accept ( ) <EOL> except socket . timeout : <EOL> self . display_no_subprocess_error ( ) <EOL> return None <EOL> self . transfer_path ( with_cwd = with_cwd ) <EOL> console . stop_readline ( ) <EOL> console . text . delete ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if was_executing : <EOL> console . write ( '<STR_LIT:\n>' ) <EOL> console . showprompt ( ) <EOL> halfbar = ( ( int ( console . width ) - <NUM_LIT:16> ) // <NUM_LIT:2> ) * '<STR_LIT:=>' <EOL> console . write ( halfbar + '<STR_LIT>' + halfbar ) <EOL> console . text . mark_set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> console . text . mark_gravity ( "<STR_LIT>" , "<STR_LIT:left>" ) <EOL> console . showprompt ( ) <EOL> if debug : <EOL> RemoteDebugger . restart_subprocess_debugger ( self . rpcclt ) <EOL> debug . load_breakpoints ( ) <EOL> self . compile . compiler . flags = self . original_compiler_flags <EOL> self . restarting = False <EOL> return self . rpcclt <EOL> def __request_interrupt ( self ) : <EOL> self . rpcclt . remotecall ( "<STR_LIT>" , "<STR_LIT>" , ( ) , { } ) <EOL> def interrupt_subprocess ( self ) : <EOL> threading . Thread ( target = self . __request_interrupt ) . start ( ) <EOL> def kill_subprocess ( self ) : <EOL> if self . _afterid is not None : <EOL> self . tkconsole . text . after_cancel ( self . _afterid ) <EOL> try : <EOL> self . rpcclt . close ( ) <EOL> except AttributeError : <EOL> pass <EOL> self . unix_terminate ( ) <EOL> self . tkconsole . executing = False <EOL> self . rpcclt = None <EOL> def unix_terminate ( self ) : <EOL> "<STR_LIT>" <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> try : <EOL> os . kill ( self . rpcpid , SIGTERM ) <EOL> except OSError : <EOL> return <EOL> else : <EOL> try : <EOL> os . waitpid ( self . rpcpid , <NUM_LIT:0> ) <EOL> except OSError : <EOL> return <EOL> def transfer_path ( self , with_cwd = False ) : <EOL> if with_cwd : <EOL> path = [ '<STR_LIT>' ] <EOL> path . extend ( sys . path ) <EOL> else : <EOL> path = sys . path <EOL> self . runcommand ( """<STR_LIT>""" % ( path , ) ) <EOL> active_seq = None <EOL> def poll_subprocess ( self ) : <EOL> clt = self . rpcclt <EOL> if clt is None : <EOL> return <EOL> try : <EOL> response = clt . pollresponse ( self . active_seq , wait = <NUM_LIT> ) <EOL> except ( EOFError , IOError , KeyboardInterrupt ) : <EOL> if self . tkconsole . closing : <EOL> return <EOL> response = None <EOL> self . restart_subprocess ( ) <EOL> if response : <EOL> self . tkconsole . resetoutput ( ) <EOL> self . active_seq = None <EOL> how , what = response <EOL> console = self . tkconsole . console <EOL> if how == "<STR_LIT:OK>" : <EOL> if what is not None : <EOL> print ( repr ( what ) , file = console ) <EOL> elif how == "<STR_LIT>" : <EOL> if self . tkconsole . getvar ( "<STR_LIT>" ) : <EOL> self . remote_stack_viewer ( ) <EOL> elif how == "<STR_LIT>" : <EOL> errmsg = "<STR_LIT>" <EOL> print ( errmsg , what , file = sys . __stderr__ ) <EOL> print ( errmsg , what , file = console ) <EOL> try : <EOL> self . tkconsole . endexecuting ( ) <EOL> except AttributeError : <EOL> pass <EOL> if not self . tkconsole . closing : <EOL> self . _afterid = self . tkconsole . text . after ( <EOL> self . tkconsole . pollinterval , self . poll_subprocess ) <EOL> debugger = None <EOL> def setdebugger ( self , debugger ) : <EOL> self . debugger = debugger <EOL> def getdebugger ( self ) : <EOL> return self . debugger <EOL> def open_remote_stack_viewer ( self ) : <EOL> """<STR_LIT>""" <EOL> self . tkconsole . text . after ( <NUM_LIT> , self . remote_stack_viewer ) <EOL> return <EOL> def remote_stack_viewer ( self ) : <EOL> from idlelib import RemoteObjectBrowser <EOL> oid = self . rpcclt . remotequeue ( "<STR_LIT>" , "<STR_LIT>" , ( "<STR_LIT>" , ) , { } ) <EOL> if oid is None : <EOL> self . tkconsole . root . bell ( ) <EOL> return <EOL> item = RemoteObjectBrowser . StubObjectTreeItem ( self . rpcclt , oid ) <EOL> from idlelib . TreeWidget import ScrolledCanvas , TreeNode <EOL> top = Toplevel ( self . tkconsole . root ) <EOL> theme = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' ) <EOL> background = idleConf . GetHighlight ( theme , '<STR_LIT>' ) [ '<STR_LIT>' ] <EOL> sc = ScrolledCanvas ( top , bg = background , highlightthickness = <NUM_LIT:0> ) <EOL> sc . frame . pack ( expand = <NUM_LIT:1> , fill = "<STR_LIT>" ) <EOL> node = TreeNode ( sc . canvas , None , item ) <EOL> node . expand ( ) <EOL> gid = <NUM_LIT:0> <EOL> def execsource ( self , source ) : <EOL> "<STR_LIT>" <EOL> filename = self . stuffsource ( source ) <EOL> self . execfile ( filename , source ) <EOL> def execfile ( self , filename , source = None ) : <EOL> "<STR_LIT>" <EOL> if source is None : <EOL> source = open ( filename , "<STR_LIT:r>" ) . read ( ) <EOL> try : <EOL> code = compile ( source , filename , "<STR_LIT>" , dont_inherit = True ) <EOL> except ( OverflowError , SyntaxError ) : <EOL> self . tkconsole . resetoutput ( ) <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> file = self . tkconsole . stderr ) <EOL> InteractiveInterpreter . showsyntaxerror ( self , filename ) <EOL> self . tkconsole . showprompt ( ) <EOL> else : <EOL> self . runcode ( code ) <EOL> def runsource ( self , source ) : <EOL> "<STR_LIT>" <EOL> filename = self . stuffsource ( source ) <EOL> self . more = <NUM_LIT:0> <EOL> self . save_warnings_filters = warnings . filters [ : ] <EOL> warnings . filterwarnings ( action = "<STR_LIT:error>" , category = SyntaxWarning ) <EOL> if isinstance ( source , unicode ) and IOBinding . encoding != '<STR_LIT:utf-8>' : <EOL> try : <EOL> source = '<STR_LIT>' % ( <EOL> IOBinding . encoding , <EOL> source . encode ( IOBinding . encoding ) ) <EOL> except UnicodeError : <EOL> self . tkconsole . resetoutput ( ) <EOL> self . write ( "<STR_LIT>" ) <EOL> return <EOL> try : <EOL> return InteractiveInterpreter . runsource ( self , source , filename ) <EOL> finally : <EOL> if self . save_warnings_filters is not None : <EOL> warnings . filters [ : ] = self . save_warnings_filters <EOL> self . save_warnings_filters = None <EOL> def stuffsource ( self , source ) : <EOL> "<STR_LIT>" <EOL> filename = "<STR_LIT>" % self . gid <EOL> self . gid = self . gid + <NUM_LIT:1> <EOL> lines = source . split ( "<STR_LIT:\n>" ) <EOL> linecache . cache [ filename ] = len ( source ) + <NUM_LIT:1> , <NUM_LIT:0> , lines , filename <EOL> return filename <EOL> def prepend_syspath ( self , filename ) : <EOL> "<STR_LIT>" <EOL> self . runcommand ( """<STR_LIT>""" % ( filename , ) ) <EOL> def showsyntaxerror ( self , filename = None ) : <EOL> """<STR_LIT>""" <EOL> text = self . tkconsole . text <EOL> stuff = self . unpackerror ( ) <EOL> if stuff : <EOL> msg , lineno , offset , line = stuff <EOL> if lineno == <NUM_LIT:1> : <EOL> pos = "<STR_LIT>" % ( offset - <NUM_LIT:1> ) <EOL> else : <EOL> pos = "<STR_LIT>" % ( lineno - <NUM_LIT:1> , offset - <NUM_LIT:1> ) <EOL> text . tag_add ( "<STR_LIT>" , pos ) <EOL> text . see ( pos ) <EOL> char = text . get ( pos ) <EOL> if char and char in IDENTCHARS : <EOL> text . tag_add ( "<STR_LIT>" , pos + "<STR_LIT>" , pos ) <EOL> self . tkconsole . resetoutput ( ) <EOL> self . write ( "<STR_LIT>" % str ( msg ) ) <EOL> else : <EOL> self . tkconsole . resetoutput ( ) <EOL> InteractiveInterpreter . showsyntaxerror ( self , filename ) <EOL> self . tkconsole . showprompt ( ) <EOL> def unpackerror ( self ) : <EOL> type , value , tb = sys . exc_info ( ) <EOL> ok = type is SyntaxError <EOL> if ok : <EOL> try : <EOL> msg , ( dummy_filename , lineno , offset , line ) = value <EOL> if not offset : <EOL> offset = <NUM_LIT:0> <EOL> except : <EOL> ok = <NUM_LIT:0> <EOL> if ok : <EOL> return msg , lineno , offset , line <EOL> else : <EOL> return None <EOL> def showtraceback ( self ) : <EOL> "<STR_LIT>" <EOL> self . tkconsole . resetoutput ( ) <EOL> self . checklinecache ( ) <EOL> InteractiveInterpreter . showtraceback ( self ) <EOL> if self . tkconsole . getvar ( "<STR_LIT>" ) : <EOL> self . tkconsole . open_stack_viewer ( ) <EOL> def checklinecache ( self ) : <EOL> c = linecache . cache <EOL> for key in c . keys ( ) : <EOL> if key [ : <NUM_LIT:1> ] + key [ - <NUM_LIT:1> : ] != "<STR_LIT>" : <EOL> del c [ key ] <EOL> def runcommand ( self , code ) : <EOL> "<STR_LIT>" <EOL> if self . tkconsole . executing : <EOL> self . display_executing_dialog ( ) <EOL> return <NUM_LIT:0> <EOL> if self . rpcclt : <EOL> self . rpcclt . remotequeue ( "<STR_LIT>" , "<STR_LIT>" , ( code , ) , { } ) <EOL> else : <EOL> exec code in self . locals <EOL> return <NUM_LIT:1> <EOL> def runcode ( self , code ) : <EOL> "<STR_LIT>" <EOL> if self . tkconsole . executing : <EOL> self . interp . restart_subprocess ( ) <EOL> self . checklinecache ( ) <EOL> if self . save_warnings_filters is not None : <EOL> warnings . filters [ : ] = self . save_warnings_filters <EOL> self . save_warnings_filters = None <EOL> debugger = self . debugger <EOL> try : <EOL> self . tkconsole . beginexecuting ( ) <EOL> if not debugger and self . rpcclt is not None : <EOL> self . active_seq = self . rpcclt . asyncqueue ( "<STR_LIT>" , "<STR_LIT>" , <EOL> ( code , ) , { } ) <EOL> elif debugger : <EOL> debugger . run ( code , self . locals ) <EOL> else : <EOL> exec code in self . locals <EOL> except SystemExit : <EOL> if not self . tkconsole . closing : <EOL> if tkMessageBox . askyesno ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> default = "<STR_LIT:yes>" , <EOL> master = self . tkconsole . text ) : <EOL> raise <EOL> else : <EOL> self . showtraceback ( ) <EOL> else : <EOL> raise <EOL> except : <EOL> if use_subprocess : <EOL> print ( "<STR_LIT>" , <EOL> file = self . tkconsole . stderr ) <EOL> self . showtraceback ( ) <EOL> self . tkconsole . endexecuting ( ) <EOL> else : <EOL> if self . tkconsole . canceled : <EOL> self . tkconsole . canceled = False <EOL> print ( "<STR_LIT>" , file = self . tkconsole . stderr ) <EOL> else : <EOL> self . showtraceback ( ) <EOL> finally : <EOL> if not use_subprocess : <EOL> try : <EOL> self . tkconsole . endexecuting ( ) <EOL> except AttributeError : <EOL> pass <EOL> def write ( self , s ) : <EOL> "<STR_LIT>" <EOL> self . tkconsole . stderr . write ( s ) <EOL> def display_port_binding_error ( self ) : <EOL> tkMessageBox . showerror ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> master = self . tkconsole . text ) <EOL> def display_no_subprocess_error ( self ) : <EOL> tkMessageBox . showerror ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> master = self . tkconsole . text ) <EOL> def display_executing_dialog ( self ) : <EOL> tkMessageBox . showerror ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> master = self . tkconsole . text ) <EOL> class PyShell ( OutputWindow ) : <EOL> shell_title = "<STR_LIT>" + python_version ( ) + "<STR_LIT>" <EOL> ColorDelegator = ModifiedColorDelegator <EOL> UndoDelegator = ModifiedUndoDelegator <EOL> menu_specs = [ <EOL> ( "<STR_LIT:file>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> from idlelib . IdleHistory import History <EOL> def __init__ ( self , flist = None ) : <EOL> if use_subprocess : <EOL> ms = self . menu_specs <EOL> if ms [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] != "<STR_LIT>" : <EOL> ms . insert ( <NUM_LIT:2> , ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . interp = ModifiedInterpreter ( self ) <EOL> if flist is None : <EOL> root = Tk ( ) <EOL> fixwordbreaks ( root ) <EOL> root . withdraw ( ) <EOL> flist = PyShellFileList ( root ) <EOL> OutputWindow . __init__ ( self , flist , None , None ) <EOL> self . usetabs = True <EOL> self . indentwidth = <NUM_LIT:8> <EOL> self . context_use_ps1 = True <EOL> text = self . text <EOL> text . configure ( wrap = "<STR_LIT>" ) <EOL> text . bind ( "<STR_LIT>" , self . enter_callback ) <EOL> text . bind ( "<STR_LIT>" , self . linefeed_callback ) <EOL> text . bind ( "<STR_LIT>" , self . cancel_callback ) <EOL> text . bind ( "<STR_LIT>" , self . eof_callback ) <EOL> text . bind ( "<STR_LIT>" , self . open_stack_viewer ) <EOL> text . bind ( "<STR_LIT>" , self . toggle_debugger ) <EOL> text . bind ( "<STR_LIT>" , self . toggle_jit_stack_viewer ) <EOL> if use_subprocess : <EOL> text . bind ( "<STR_LIT>" , self . view_restart_mark ) <EOL> text . bind ( "<STR_LIT>" , self . restart_shell ) <EOL> self . save_stdout = sys . stdout <EOL> self . save_stderr = sys . stderr <EOL> self . save_stdin = sys . stdin <EOL> from idlelib import IOBinding <EOL> self . stdin = PseudoInputFile ( self , "<STR_LIT>" , IOBinding . encoding ) <EOL> self . stdout = PseudoOutputFile ( self , "<STR_LIT>" , IOBinding . encoding ) <EOL> self . stderr = PseudoOutputFile ( self , "<STR_LIT>" , IOBinding . encoding ) <EOL> self . console = PseudoOutputFile ( self , "<STR_LIT>" , IOBinding . encoding ) <EOL> if not use_subprocess : <EOL> sys . stdout = self . stdout <EOL> sys . stderr = self . stderr <EOL> sys . stdin = self . stdin <EOL> self . history = self . History ( self . text ) <EOL> self . pollinterval = <NUM_LIT:50> <EOL> def get_standard_extension_names ( self ) : <EOL> return idleConf . GetExtensions ( shell_only = True ) <EOL> reading = False <EOL> executing = False <EOL> canceled = False <EOL> endoffile = False <EOL> closing = False <EOL> _stop_readline_flag = False <EOL> def set_warning_stream ( self , stream ) : <EOL> global warning_stream <EOL> warning_stream = stream <EOL> def get_warning_stream ( self ) : <EOL> return warning_stream <EOL> def toggle_debugger ( self , event = None ) : <EOL> if self . executing : <EOL> tkMessageBox . showerror ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> master = self . text ) <EOL> self . set_debugger_indicator ( ) <EOL> return "<STR_LIT>" <EOL> else : <EOL> db = self . interp . getdebugger ( ) <EOL> if db : <EOL> self . close_debugger ( ) <EOL> else : <EOL> self . open_debugger ( ) <EOL> def set_debugger_indicator ( self ) : <EOL> db = self . interp . getdebugger ( ) <EOL> self . setvar ( "<STR_LIT>" , not not db ) <EOL> def toggle_jit_stack_viewer ( self , event = None ) : <EOL> pass <EOL> def close_debugger ( self ) : <EOL> db = self . interp . getdebugger ( ) <EOL> if db : <EOL> self . interp . setdebugger ( None ) <EOL> db . close ( ) <EOL> if self . interp . rpcclt : <EOL> RemoteDebugger . close_remote_debugger ( self . interp . rpcclt ) <EOL> self . resetoutput ( ) <EOL> self . console . write ( "<STR_LIT>" ) <EOL> sys . ps1 = "<STR_LIT>" <EOL> self . showprompt ( ) <EOL> self . set_debugger_indicator ( ) <EOL> def open_debugger ( self ) : <EOL> if self . interp . rpcclt : <EOL> dbg_gui = RemoteDebugger . start_remote_debugger ( self . interp . rpcclt , <EOL> self ) <EOL> else : <EOL> dbg_gui = Debugger . Debugger ( self ) <EOL> self . interp . setdebugger ( dbg_gui ) <EOL> dbg_gui . load_breakpoints ( ) <EOL> sys . ps1 = "<STR_LIT>" <EOL> self . showprompt ( ) <EOL> self . set_debugger_indicator ( ) <EOL> def beginexecuting ( self ) : <EOL> "<STR_LIT>" <EOL> self . resetoutput ( ) <EOL> self . executing = <NUM_LIT:1> <EOL> def endexecuting ( self ) : <EOL> "<STR_LIT>" <EOL> self . executing = <NUM_LIT:0> <EOL> self . canceled = <NUM_LIT:0> <EOL> self . showprompt ( ) <EOL> def close ( self ) : <EOL> "<STR_LIT>" <EOL> if self . executing : <EOL> response = tkMessageBox . askokcancel ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> default = "<STR_LIT>" , <EOL> parent = self . text ) <EOL> if response is False : <EOL> return "<STR_LIT>" <EOL> self . stop_readline ( ) <EOL> self . canceled = True <EOL> self . closing = True <EOL> return EditorWindow . close ( self ) <EOL> def _close ( self ) : <EOL> "<STR_LIT>" <EOL> self . close_debugger ( ) <EOL> if use_subprocess : <EOL> self . interp . kill_subprocess ( ) <EOL> sys . stdout = self . save_stdout <EOL> sys . stderr = self . save_stderr <EOL> sys . stdin = self . save_stdin <EOL> self . interp = None <EOL> self . console = None <EOL> self . flist . pyshell = None <EOL> self . history = None <EOL> EditorWindow . _close ( self ) <EOL> def ispythonsource ( self , filename ) : <EOL> "<STR_LIT>" <EOL> return True <EOL> def short_title ( self ) : <EOL> return self . shell_title <EOL> COPYRIGHT = '<STR_LIT>' <EOL> def begin ( self ) : <EOL> self . resetoutput ( ) <EOL> if use_subprocess : <EOL> nosub = '<STR_LIT>' <EOL> client = self . interp . start_subprocess ( ) <EOL> if not client : <EOL> self . close ( ) <EOL> return False <EOL> else : <EOL> nosub = "<STR_LIT>" <EOL> self . write ( "<STR_LIT>" % <EOL> ( sys . version , sys . platform , self . COPYRIGHT , nosub ) ) <EOL> self . showprompt ( ) <EOL> import Tkinter <EOL> Tkinter . _default_root = None <EOL> return True <EOL> def stop_readline ( self ) : <EOL> if not self . reading : <EOL> return <EOL> self . _stop_readline_flag = True <EOL> self . top . quit ( ) <EOL> def readline ( self ) : <EOL> save = self . reading <EOL> try : <EOL> self . reading = <NUM_LIT:1> <EOL> self . top . mainloop ( ) <EOL> finally : <EOL> self . reading = save <EOL> if self . _stop_readline_flag : <EOL> self . _stop_readline_flag = False <EOL> return "<STR_LIT>" <EOL> line = self . text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if len ( line ) == <NUM_LIT:0> : <EOL> line = "<STR_LIT:\n>" <EOL> if isinstance ( line , unicode ) : <EOL> from idlelib import IOBinding <EOL> try : <EOL> line = line . encode ( IOBinding . encoding ) <EOL> except UnicodeError : <EOL> pass <EOL> self . resetoutput ( ) <EOL> if self . canceled : <EOL> self . canceled = <NUM_LIT:0> <EOL> if not use_subprocess : <EOL> raise KeyboardInterrupt <EOL> if self . endoffile : <EOL> self . endoffile = <NUM_LIT:0> <EOL> line = "<STR_LIT>" <EOL> return line <EOL> def isatty ( self ) : <EOL> return True <EOL> def cancel_callback ( self , event = None ) : <EOL> try : <EOL> if self . text . compare ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> return <EOL> except : <EOL> pass <EOL> if not ( self . executing or self . reading ) : <EOL> self . resetoutput ( ) <EOL> self . interp . write ( "<STR_LIT>" ) <EOL> self . showprompt ( ) <EOL> return "<STR_LIT>" <EOL> self . endoffile = <NUM_LIT:0> <EOL> self . canceled = <NUM_LIT:1> <EOL> if ( self . executing and self . interp . rpcclt ) : <EOL> if self . interp . getdebugger ( ) : <EOL> self . interp . restart_subprocess ( ) <EOL> else : <EOL> self . interp . interrupt_subprocess ( ) <EOL> if self . reading : <EOL> self . top . quit ( ) <EOL> return "<STR_LIT>" <EOL> def eof_callback ( self , event ) : <EOL> if self . executing and not self . reading : <EOL> return <EOL> if not ( self . text . compare ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) and <EOL> self . text . compare ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) : <EOL> return <EOL> if not self . executing : <EOL> self . resetoutput ( ) <EOL> self . close ( ) <EOL> else : <EOL> self . canceled = <NUM_LIT:0> <EOL> self . endoffile = <NUM_LIT:1> <EOL> self . top . quit ( ) <EOL> return "<STR_LIT>" <EOL> def linefeed_callback ( self , event ) : <EOL> if self . reading : <EOL> self . text . insert ( "<STR_LIT>" , "<STR_LIT:\n>" ) <EOL> self . text . see ( "<STR_LIT>" ) <EOL> else : <EOL> self . newline_and_indent_event ( event ) <EOL> return "<STR_LIT>" <EOL> def enter_callback ( self , event ) : <EOL> if self . executing and not self . reading : <EOL> return <EOL> try : <EOL> sel = self . text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if sel : <EOL> if self . text . compare ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . recall ( sel , event ) <EOL> return "<STR_LIT>" <EOL> except : <EOL> pass <EOL> if self . text . compare ( "<STR_LIT>" , "<STR_LIT:<>" , "<STR_LIT>" ) : <EOL> prev = self . text . tag_prevrange ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if prev and self . text . compare ( "<STR_LIT>" , "<STR_LIT:<>" , prev [ <NUM_LIT:1> ] ) : <EOL> self . recall ( self . text . get ( prev [ <NUM_LIT:0> ] , prev [ <NUM_LIT:1> ] ) , event ) <EOL> return "<STR_LIT>" <EOL> next = self . text . tag_nextrange ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if next and self . text . compare ( "<STR_LIT>" , "<STR_LIT>" , next [ <NUM_LIT:0> ] ) : <EOL> self . recall ( self . text . get ( next [ <NUM_LIT:0> ] , next [ <NUM_LIT:1> ] ) , event ) <EOL> return "<STR_LIT>" <EOL> indices = self . text . tag_nextrange ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if indices and self . text . compare ( indices [ <NUM_LIT:0> ] , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . recall ( self . text . get ( indices [ <NUM_LIT:1> ] , "<STR_LIT>" ) , event ) <EOL> else : <EOL> self . recall ( self . text . get ( "<STR_LIT>" , "<STR_LIT>" ) , event ) <EOL> return "<STR_LIT>" <EOL> if self . text . compare ( "<STR_LIT>" , "<STR_LIT:<>" , "<STR_LIT>" ) : <EOL> self . text . mark_set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> s = self . text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if s and not s . strip ( ) : <EOL> self . text . delete ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if self . text . compare ( "<STR_LIT>" , "<STR_LIT:<>" , "<STR_LIT>" ) : <EOL> self . newline_and_indent_event ( event ) <EOL> return "<STR_LIT>" <EOL> self . text . mark_set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if self . reading : <EOL> self . text . insert ( "<STR_LIT>" , "<STR_LIT:\n>" ) <EOL> self . text . see ( "<STR_LIT>" ) <EOL> else : <EOL> self . newline_and_indent_event ( event ) <EOL> self . text . tag_add ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . text . update_idletasks ( ) <EOL> if self . reading : <EOL> self . top . quit ( ) <EOL> else : <EOL> self . runit ( ) <EOL> return "<STR_LIT>" <EOL> def recall ( self , s , event ) : <EOL> s = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , s ) <EOL> s = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , s ) <EOL> lines = s . split ( '<STR_LIT:\n>' ) <EOL> self . text . undo_block_start ( ) <EOL> try : <EOL> self . text . tag_remove ( "<STR_LIT>" , "<STR_LIT:1.0>" , "<STR_LIT:end>" ) <EOL> self . text . mark_set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> prefix = self . text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if prefix . rstrip ( ) . endswith ( '<STR_LIT::>' ) : <EOL> self . newline_and_indent_event ( event ) <EOL> prefix = self . text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . text . insert ( "<STR_LIT>" , lines [ <NUM_LIT:0> ] . strip ( ) ) <EOL> if len ( lines ) > <NUM_LIT:1> : <EOL> orig_base_indent = re . search ( r'<STR_LIT>' , lines [ <NUM_LIT:0> ] ) . group ( <NUM_LIT:0> ) <EOL> new_base_indent = re . search ( r'<STR_LIT>' , prefix ) . group ( <NUM_LIT:0> ) <EOL> for line in lines [ <NUM_LIT:1> : ] : <EOL> if line . startswith ( orig_base_indent ) : <EOL> line = new_base_indent + line [ len ( orig_base_indent ) : ] <EOL> self . text . insert ( '<STR_LIT>' , '<STR_LIT:\n>' + line . rstrip ( ) ) <EOL> finally : <EOL> self . text . see ( "<STR_LIT>" ) <EOL> self . text . undo_block_stop ( ) <EOL> def runit ( self ) : <EOL> line = self . text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> i = len ( line ) <EOL> while i > <NUM_LIT:0> and line [ i - <NUM_LIT:1> ] in "<STR_LIT>" : <EOL> i = i - <NUM_LIT:1> <EOL> if i > <NUM_LIT:0> and line [ i - <NUM_LIT:1> ] == "<STR_LIT:\n>" : <EOL> i = i - <NUM_LIT:1> <EOL> while i > <NUM_LIT:0> and line [ i - <NUM_LIT:1> ] in "<STR_LIT>" : <EOL> i = i - <NUM_LIT:1> <EOL> line = line [ : i ] <EOL> self . interp . runsource ( line ) <EOL> def open_stack_viewer ( self , event = None ) : <EOL> if self . interp . rpcclt : <EOL> return self . interp . remote_stack_viewer ( ) <EOL> try : <EOL> sys . last_traceback <EOL> except : <EOL> tkMessageBox . showerror ( "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> master = self . text ) <EOL> return <EOL> from idlelib . StackViewer import StackBrowser <EOL> StackBrowser ( self . root , self . flist ) <EOL> def view_restart_mark ( self , event = None ) : <EOL> self . text . see ( "<STR_LIT>" ) <EOL> self . text . see ( "<STR_LIT>" ) <EOL> def restart_shell ( self , event = None ) : <EOL> "<STR_LIT>" <EOL> self . interp . restart_subprocess ( with_cwd = True ) <EOL> def showprompt ( self ) : <EOL> self . resetoutput ( ) <EOL> try : <EOL> s = str ( sys . ps1 ) <EOL> except : <EOL> s = "<STR_LIT>" <EOL> self . console . write ( s ) <EOL> self . text . mark_set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . set_line_and_column ( ) <EOL> self . io . reset_undo ( ) <EOL> def resetoutput ( self ) : <EOL> source = self . text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if self . history : <EOL> self . history . store ( source ) <EOL> if self . text . get ( "<STR_LIT>" ) != "<STR_LIT:\n>" : <EOL> self . text . insert ( "<STR_LIT>" , "<STR_LIT:\n>" ) <EOL> self . text . mark_set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . set_line_and_column ( ) <EOL> sys . stdout . softspace = <NUM_LIT:0> <EOL> def write ( self , s , tags = ( ) ) : <EOL> try : <EOL> self . text . mark_gravity ( "<STR_LIT>" , "<STR_LIT:right>" ) <EOL> OutputWindow . write ( self , s , tags , "<STR_LIT>" ) <EOL> self . text . mark_gravity ( "<STR_LIT>" , "<STR_LIT:left>" ) <EOL> except : <EOL> pass <EOL> if self . canceled : <EOL> self . canceled = <NUM_LIT:0> <EOL> if not use_subprocess : <EOL> raise KeyboardInterrupt <EOL> def rmenu_check_cut ( self ) : <EOL> try : <EOL> if self . text . compare ( '<STR_LIT>' , '<STR_LIT:<>' , '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> except TclError : <EOL> return '<STR_LIT>' <EOL> return super ( PyShell , self ) . rmenu_check_cut ( ) <EOL> def rmenu_check_paste ( self ) : <EOL> if self . text . compare ( '<STR_LIT>' , '<STR_LIT:<>' , '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> return super ( PyShell , self ) . rmenu_check_paste ( ) <EOL> class PseudoFile ( io . TextIOBase ) : <EOL> def __init__ ( self , shell , tags , encoding = None ) : <EOL> self . shell = shell <EOL> self . tags = tags <EOL> self . softspace = <NUM_LIT:0> <EOL> self . _encoding = encoding <EOL> @ property <EOL> def encoding ( self ) : <EOL> return self . _encoding <EOL> @ property <EOL> def name ( self ) : <EOL> return '<STR_LIT>' % self . tags <EOL> def isatty ( self ) : <EOL> return True <EOL> class PseudoOutputFile ( PseudoFile ) : <EOL> def writable ( self ) : <EOL> return True <EOL> def write ( self , s ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if type ( s ) not in ( unicode , str , bytearray ) : <EOL> if isinstance ( s , unicode ) : <EOL> s = unicode . __getitem__ ( s , slice ( None ) ) <EOL> elif isinstance ( s , str ) : <EOL> s = str . __str__ ( s ) <EOL> elif isinstance ( s , bytearray ) : <EOL> s = bytearray . __str__ ( s ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' + type ( s ) . __name__ ) <EOL> return self . shell . write ( s , self . tags ) <EOL> class PseudoInputFile ( PseudoFile ) : <EOL> def __init__ ( self , shell , tags , encoding = None ) : <EOL> PseudoFile . __init__ ( self , shell , tags , encoding ) <EOL> self . _line_buffer = '<STR_LIT>' <EOL> def readable ( self ) : <EOL> return True <EOL> def read ( self , size = - <NUM_LIT:1> ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if size is None : <EOL> size = - <NUM_LIT:1> <EOL> elif not isinstance ( size , int ) : <EOL> raise TypeError ( '<STR_LIT>' + type ( size ) . __name__ ) <EOL> result = self . _line_buffer <EOL> self . _line_buffer = '<STR_LIT>' <EOL> if size < <NUM_LIT:0> : <EOL> while True : <EOL> line = self . shell . readline ( ) <EOL> if not line : break <EOL> result += line <EOL> else : <EOL> while len ( result ) < size : <EOL> line = self . shell . readline ( ) <EOL> if not line : break <EOL> result += line <EOL> self . _line_buffer = result [ size : ] <EOL> result = result [ : size ] <EOL> return result <EOL> def readline ( self , size = - <NUM_LIT:1> ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if size is None : <EOL> size = - <NUM_LIT:1> <EOL> elif not isinstance ( size , int ) : <EOL> raise TypeError ( '<STR_LIT>' + type ( size ) . __name__ ) <EOL> line = self . _line_buffer or self . shell . readline ( ) <EOL> if size < <NUM_LIT:0> : <EOL> size = len ( line ) <EOL> eol = line . find ( '<STR_LIT:\n>' , <NUM_LIT:0> , size ) <EOL> if eol >= <NUM_LIT:0> : <EOL> size = eol + <NUM_LIT:1> <EOL> self . _line_buffer = line [ size : ] <EOL> return line [ : size ] <EOL> def close ( self ) : <EOL> self . shell . close ( ) <EOL> usage_msg = """<STR_LIT>""" <EOL> def main ( ) : <EOL> global flist , root , use_subprocess <EOL> capture_warnings ( True ) <EOL> use_subprocess = True <EOL> enable_shell = False <EOL> enable_edit = False <EOL> debug = False <EOL> cmd = None <EOL> script = None <EOL> startup = False <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , "<STR_LIT>" ) <EOL> except getopt . error as msg : <EOL> print ( "<STR_LIT>" % ( msg , usage_msg ) , file = sys . stderr ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> for o , a in opts : <EOL> if o == '<STR_LIT:-c>' : <EOL> cmd = a <EOL> enable_shell = True <EOL> if o == '<STR_LIT>' : <EOL> debug = True <EOL> enable_shell = True <EOL> if o == '<STR_LIT>' : <EOL> enable_edit = True <EOL> if o == '<STR_LIT>' : <EOL> sys . stdout . write ( usage_msg ) <EOL> sys . exit ( ) <EOL> if o == '<STR_LIT>' : <EOL> enable_shell = True <EOL> if o == '<STR_LIT>' : <EOL> use_subprocess = False <EOL> if o == '<STR_LIT>' : <EOL> script = a <EOL> if os . path . isfile ( script ) : <EOL> pass <EOL> else : <EOL> print ( "<STR_LIT>" , script , file = sys . stderr ) <EOL> sys . exit ( ) <EOL> enable_shell = True <EOL> if o == '<STR_LIT>' : <EOL> startup = True <EOL> enable_shell = True <EOL> if o == '<STR_LIT>' : <EOL> PyShell . shell_title = a <EOL> enable_shell = True <EOL> if args and args [ <NUM_LIT:0> ] == '<STR_LIT:->' : <EOL> cmd = sys . stdin . read ( ) <EOL> enable_shell = True <EOL> for i in range ( len ( sys . path ) ) : <EOL> sys . path [ i ] = os . path . abspath ( sys . path [ i ] ) <EOL> if args and args [ <NUM_LIT:0> ] == '<STR_LIT:->' : <EOL> sys . argv = [ '<STR_LIT>' ] + args [ <NUM_LIT:1> : ] <EOL> elif cmd : <EOL> sys . argv = [ '<STR_LIT:-c>' ] + args <EOL> elif script : <EOL> sys . argv = [ script ] + args <EOL> elif args : <EOL> enable_edit = True <EOL> pathx = [ ] <EOL> for filename in args : <EOL> pathx . append ( os . path . dirname ( filename ) ) <EOL> for dir in pathx : <EOL> dir = os . path . abspath ( dir ) <EOL> if dir not in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , dir ) <EOL> else : <EOL> dir = os . getcwd ( ) <EOL> if not dir in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , dir ) <EOL> edit_start = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , type = '<STR_LIT:bool>' ) <EOL> enable_edit = enable_edit or edit_start <EOL> enable_shell = enable_shell or not enable_edit <EOL> root = Tk ( className = "<STR_LIT>" ) <EOL> icondir = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> if system ( ) == '<STR_LIT>' : <EOL> iconfile = os . path . join ( icondir , '<STR_LIT>' ) <EOL> root . wm_iconbitmap ( default = iconfile ) <EOL> elif TkVersion >= <NUM_LIT> : <EOL> ext = '<STR_LIT>' if TkVersion >= <NUM_LIT> else '<STR_LIT>' <EOL> iconfiles = [ os . path . join ( icondir , '<STR_LIT>' % ( size , ext ) ) <EOL> for size in ( <NUM_LIT:16> , <NUM_LIT:32> , <NUM_LIT> ) ] <EOL> icons = [ PhotoImage ( file = iconfile ) for iconfile in iconfiles ] <EOL> root . tk . call ( '<STR_LIT>' , '<STR_LIT>' , str ( root ) , "<STR_LIT>" , * icons ) <EOL> fixwordbreaks ( root ) <EOL> root . withdraw ( ) <EOL> flist = PyShellFileList ( root ) <EOL> macosxSupport . setupApp ( root , flist ) <EOL> if enable_edit : <EOL> if not ( cmd or script ) : <EOL> for filename in args [ : ] : <EOL> if flist . open ( filename ) is None : <EOL> args . remove ( filename ) <EOL> if not args : <EOL> flist . new ( ) <EOL> if enable_shell : <EOL> shell = flist . open_shell ( ) <EOL> if not shell : <EOL> return <EOL> if macosxSupport . isAquaTk ( ) and flist . dict : <EOL> shell . top . lower ( ) <EOL> else : <EOL> shell = flist . pyshell <EOL> if debug : <EOL> shell . open_debugger ( ) <EOL> if startup : <EOL> filename = os . environ . get ( "<STR_LIT>" ) or os . environ . get ( "<STR_LIT>" ) <EOL> if filename and os . path . isfile ( filename ) : <EOL> shell . interp . execfile ( filename ) <EOL> if cmd or script : <EOL> shell . interp . runcommand ( """<STR_LIT>""" % ( sys . argv , ) ) <EOL> if cmd : <EOL> shell . interp . execsource ( cmd ) <EOL> elif script : <EOL> shell . interp . prepend_syspath ( script ) <EOL> shell . interp . execfile ( script ) <EOL> elif shell : <EOL> tkversionwarning = macosxSupport . tkVersionWarning ( root ) <EOL> if tkversionwarning : <EOL> shell . interp . runcommand ( "<STR_LIT>" % tkversionwarning ) <EOL> while flist . inversedict : <EOL> root . mainloop ( ) <EOL> root . destroy ( ) <EOL> capture_warnings ( False ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . modules [ '<STR_LIT>' ] = sys . modules [ '<STR_LIT:__main__>' ] <EOL> main ( ) <EOL> capture_warnings ( False ) </s>
