@@ -67,9 +67,11 @@ def __init__(self, locals=None, encoding=sys.getdefaultencoding()):
6767
6868 if not py3 :
6969
70- def runsource (self , source , filename = '<input>' , symbol = 'single' ):
71- source = '# coding: %s\n %s' % (self .encoding ,
72- source .encode (self .encoding ))
70+ def runsource (self , source , filename = '<input>' , symbol = 'single' ,
71+ encode = True ):
72+ if encode :
73+ source = '# coding: %s\n %s' % (self .encoding ,
74+ source .encode (self .encoding ))
7375 return code .InteractiveInterpreter .runsource (self , source ,
7476 filename , symbol )
7577
@@ -111,10 +113,10 @@ def showtraceback(self):
111113 tblist = traceback .extract_tb (tb )
112114 del tblist [:1 ]
113115 # Set the right lineno (encoding header adds an extra line)
114- lineno = tblist [0 ][1 ]
115116 if not py3 :
116- lineno -= 1
117- tblist [0 ] = (tblist [0 ][0 ], lineno ) + tblist [0 ][2 :]
117+ for i , (filename , lineno , module , something ) in enumerate (tblist ):
118+ if filename == '<input>' :
119+ tblist [i ] = (filename , lineno - 1 , module , something )
118120
119121 l = traceback .format_list (tblist )
120122 if l :
@@ -300,13 +302,15 @@ def __init__(self, interp, config, idle=None):
300302 if os .path .exists (pythonhist ):
301303 self .rl_history .load (pythonhist , getpreferredencoding ())
302304
303- # This was a feature request to have the PYTHONSTARTUP
304- # file executed on startup - I personally don't use this
305- # feature so please notify me of any breakage.
305+ def startup (self ):
306+ """
307+ Execute PYTHONSTARTUP file if it exits. Call this after front
308+ end-specific initialisation.
309+ """
306310 filename = os .environ .get ('PYTHONSTARTUP' )
307311 if filename and os .path .isfile (filename ):
308312 with open (filename , 'r' ) as f :
309- self .interp .runsource (f .read (), filename , 'exec' )
313+ self .interp .runsource (f .read (), filename , 'exec' , encode = False )
310314
311315 def attr_matches (self , text ):
312316 """Taken from rlcompleter.py and bent to my will."""
0 commit comments