2727import getopt
2828import re
2929import protocol
30+ import warnings
3031
3132import linecache
3233from code import InteractiveInterpreter
@@ -146,7 +147,7 @@ def recolorize_main(self):
146147 "stderr" : cconf .getcolor ("stderr" ),
147148 "console" : cconf .getcolor ("console" ),
148149 "ERROR" : cconf .getcolor ("ERROR" ),
149- None : cconf .getcolor ("normal" ),
150+ None : cconf .getcolor ("normal" ),
150151 })
151152
152153
@@ -178,6 +179,7 @@ def __init__(self, tkconsole):
178179 self .tkconsole = tkconsole
179180 locals = sys .modules ['__main__' ].__dict__
180181 InteractiveInterpreter .__init__ (self , locals = locals )
182+ self .save_warnings_filters = None
181183
182184 gid = 0
183185
@@ -202,7 +204,14 @@ def runsource(self, source):
202204 # Extend base class to stuff the source in the line cache first
203205 filename = self .stuffsource (source )
204206 self .more = 0
205- return InteractiveInterpreter .runsource (self , source , filename )
207+ self .save_warnings_filters = warnings .filters [:]
208+ warnings .filterwarnings (action = "error" , category = SyntaxWarning )
209+ try :
210+ return InteractiveInterpreter .runsource (self , source , filename )
211+ finally :
212+ if self .save_warnings_filters is not None :
213+ warnings .filters [:] = self .save_warnings_filters
214+ self .save_warnings_filters = None
206215
207216 def stuffsource (self , source ):
208217 # Stuff source in the filename cache
@@ -271,6 +280,9 @@ def getdebugger(self):
271280
272281 def runcode (self , code ):
273282 # Override base class method
283+ if self .save_warnings_filters is not None :
284+ warnings .filters [:] = self .save_warnings_filters
285+ self .save_warnings_filters = None
274286 debugger = self .debugger
275287 try :
276288 self .tkconsole .beginexecuting ()
@@ -451,10 +463,13 @@ def ispythonsource(self, filename):
451463 def short_title (self ):
452464 return self .shell_title
453465
466+ COPYRIGHT = \
467+ 'Type "copyright", "credits" or "license" for more information.'
468+
454469 def begin (self ):
455470 self .resetoutput ()
456471 self .write ("Python %s on %s\n %s\n IDLE %s -- press F1 for help\n " %
457- (sys .version , sys .platform , sys . copyright ,
472+ (sys .version , sys .platform , self . COPYRIGHT ,
458473 idlever .IDLE_VERSION ))
459474 try :
460475 sys .ps1
@@ -790,12 +805,6 @@ def main( self, argv ):
790805
791806 if noshell : edit = 1
792807
793- if not edit :
794- if cmd :
795- sys .argv = ["-c" ] + args
796- else :
797- sys .argv = args or ["" ]
798-
799808 for i in range (len (sys .path )):
800809 sys .path [i ] = os .path .abspath (sys .path [i ])
801810
@@ -813,7 +822,7 @@ def main( self, argv ):
813822 sys .path .insert (0 , dir )
814823
815824 global flist , root
816- root = Tk ()
825+ root = Tk (className = "Idle" )
817826 fixwordbreaks (root )
818827 root .withdraw ()
819828 flist = PyShellFileList (root )
@@ -823,7 +832,12 @@ def main( self, argv ):
823832 flist .open (filename )
824833 if not args :
825834 flist .new ()
826-
835+ else :
836+ if cmd :
837+ sys .argv = ["-c" ] + args
838+ else :
839+ sys .argv = args or ["" ]
840+
827841 #dbg=OnDemandOutputWindow(flist)
828842 #dbg.set_title('Internal IDLE Problem')
829843 #sys.stdout = PseudoFile(dbg,['stdout'])
0 commit comments